当客户在 WooCommerce 中购买产品时,在最终结帐页面上获取订单 ID
Get the order ID on the final checkout page when a customer purchased a product in WooCommerce
我正在开发一个插件,需要在客户购买产品时在最终结帐页面上获取订单 ID。我怎么做?
我试过了
global $order
var_dump($order);
而我只看到 "DESC"。我需要访问正在查看该页面的客户的当前订单。
我需要在前端获取订单 ID 并将该 ID 添加到脚本中,也在前端,这样当客户订购产品并付款时,页面就会加载,向他们显示 "Thank you, here is your order number: 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 );
我正在开发一个插件,需要在客户购买产品时在最终结帐页面上获取订单 ID。我怎么做? 我试过了
global $order
var_dump($order);
而我只看到 "DESC"。我需要访问正在查看该页面的客户的当前订单。
我需要在前端获取订单 ID 并将该 ID 添加到脚本中,也在前端,这样当客户订购产品并付款时,页面就会加载,向他们显示 "Thank you, here is your order number: 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 );