[英]Get the order id on WooCommerce “Order received” Thankyou page
I will customize the thankyou page from my WoocCommerce shop.我将从我的 WoocCommerce 商店自定义感谢页面。 For this I added a blanc thankyou.php into the WooCommerce checkout directory.
为此,我在 WooCommerce 结帐目录中添加了一个 blancthankyou.php。
I tried this code我试过这段代码
function get_order($order_id) {
echo $order_id;
}
add_action('woocommerce_thankyou', 'get_order');
But the variable $order_id is empty.但是变量 $order_id 是空的。
Is there somebody who knows how I get the order id on the thankyou page?有人知道我如何在谢谢页面上获得订单 ID 吗?
If Url is like www.example.com/checkout/order-received/1234/?key=wc_order_s5ou6md6nTZDds
you can use the following to get the order id:如果 Url 类似于
www.example.com/checkout/order-received/1234/?key=wc_order_s5ou6md6nTZDds
您可以使用以下命令获取订单 ID:
global $wp;
if ( isset($wp->query_vars['order-received']) ) {
$order_id = absint($wp->query_vars['order-received']); // The order ID
$order = wc_get_order( $order_id ); // The WC_Order object
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.