【问题标题】:Get custom parameter from URL in functions.php从functions.php中的URL获取自定义参数
【发布时间】:2017-07-25 02:23:58
【问题描述】:

要点是: wordpress 向 personX 发送“收到订单”邮件,邮件包含一个链接(应该将订单状态设置为“已完成”),在链接中我输入了 orderID,以便我可以检索它并使用此代码更改订单状态:

    //-> insert code that last few characters of URL and put that in $order_id

    // Get order
        $order = wc_get_order( $order_id );

    // Update order to completed status
        $order->update_status( 'completed' );

当我单击 personX 在邮件中收到的链接时(默认的 woocommerce 订单收到邮件 + 我的自定义链接到此打印屏幕上的自定义页面:https://snag.gy/Nyhkcu.jpg)并回显页面的当前 URL,它不会回显query_string(?后面的部分)。

我这样构建了 url 字符串:

<a href="'. admin_url( '/orderConfirmationPage/?orderId=' . absint( $order->id )  ) .'" >

无论如何要将订单 ID 回显到页面? (所以我可以尝试测试第一个代码块中的代码)

【问题讨论】:

标签: php wordpress email url query-string


【解决方案1】:

您的字符串在回显标签和管理 URL 时中断,也不正确 改成下面这样的

$added_string = "?orderId=".$order->id;
$admin_url = get_permalink( get_page_by_title('orderConfirmationPage') );
echo '<a href="'.admin_url( $admin_url ).''.$added_string'" ></a>';

【讨论】:

  • 嘿,感谢我尝试过的答案,但它把我带到了/wp-admin/www.mysite.nl/orderconfirmationpage。所以没用:/把它改成这个(并且有效):$add_string = "?orderId=".$order->id; $admin_url = get_permalink(get_page_by_title('orderconfirmationpage')); $link3 .= '';但仍然无法将订单 ID 回显到它重定向到的页面。
  • $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; var_dump($actual_link);
  • 嗨,你提到你的 URL 将是这个 "/wp-admin/www.mysite.nl/orderconfirmationpage" & 它不起作用然后只需删除 admin_url() 函数并使其像 href=" '.$admin_url.''.$added_string'"。这对你有用。
猜你喜欢
  • 1970-01-01
  • 2016-10-07
  • 2013-10-07
  • 1970-01-01
  • 2013-06-08
  • 2014-01-06
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多