【问题标题】:Get the order ID on the final checkout page when a customer purchased a product in WooCommerce当客户在 WooCommerce 中购买产品时,在最终结帐页面上获取订单 ID
【发布时间】:2020-06-08 15:02:30
【问题描述】:

我正在开发一个插件,当客户购买产品时,该插件需要在最终结帐页面上获取订单 ID。我怎么做? 我试过了

global $order
var_dump($order);

我看到的只是“DESC”。我需要访问正在查看该页面的客户的当前订单。

我需要在前端获取订单 ID 并将该 ID 添加到脚本中,同样在前端,这样当客户订购产品并付款时,页面将加载,向他们显示“谢谢,这是您的订单号:xxx"。那时我需要我的脚本,例如,执行console.log("The oder ID is:", order_id);

【问题讨论】:

    标签: wordpress woocommerce checkout orders


    【解决方案1】:

    要在客户购买产品时在最终结帐页面上获取订单 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 ); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多