当客户在WooCommerce中购买产品时,在最终结账页面上获取订单ID [英] Get the order ID on the final checkout page when a customer purchased a product in WooCommerce
本文介绍了当客户在WooCommerce中购买产品时,在最终结账页面上获取订单ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个插件,当客户购买产品时,它需要在最后的结账页面上获得订单ID。我该怎么做? 我试过了
global $order
var_dump($order);
我看到的都是"DESC"。我需要访问正在查看该页面的客户的当前订单。
我需要在前端获得订单ID,并将该ID添加到脚本中,也是在前端,以便当客户订购产品并付款时,页面将加载,向他们显示"谢谢,这是您的订单号:xxx"。例如,此时我需要我的脚本来执行console.log("The oder ID is:", order_id);
推荐答案
若要在客户购买产品时在最终结账页上获取订单ID,可以使用woocommerce_thankyou
挂钩,其中回调函数已包含订单ID。
// define the woocommerce_thankyou callback
function action_woocommerce_thankyou( $order_id ) {
echo "Thank you, here is your order ID: " . $order_id;
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Customer billing country
$billing_country = $order->get_billing_country();
// etc..
};
// add the action
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );
这篇关于当客户在WooCommerce中购买产品时,在最终结账页面上获取订单ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文