【问题标题】:How to retrieve order ID on Order Pay page in WooCommerce如何在 WooCommerce 的订单支付页面上检索订单 ID
【发布时间】:2021-02-12 22:06:24
【问题描述】:

我正在尝试修改 Woocomerce 结帐页面以处理失败或待付款的订单。在这些订单上,系统结账时已经生成了一个订单,但我无法从 form_checkout.php 模板中检索到该订单的 ID。

客户可以使用 Woocommerce URL 支付失败的订单,类似于以下:

https://myurl.com/checkout/order-pay/XXXXX/?pay_for_order=true&key=wc_order_XXXXXXXXXXXX&subscription_renewal=true

我也不使用 $_GET 检索变量,因为访问时 URL 会转换为 https://myurl.com/checkout。我不知道你是否丢失了这些数据,或者我可以在哪里收集它。

这可能吗?

【问题讨论】:

    标签: php wordpress woocommerce orders woocommerce-subscriptions


    【解决方案1】:

    要在订单支付页面上检索订单 ID,您将使用以下内容:

    global $wp;
    
    if ( isset($wp->query_vars['order-pay']) && absint($wp->query_vars['order-pay']) > 0 ) {
        $order_id = absint($wp->query_vars['order-pay']); // The order ID
    
        $order    = wc_get_order( $order_id ); // Get the WC_Order Object instance
    }
    

    注意:要定位订单支付页面,可以使用is_wc_endpoint_url('order-pay')条件标签。

    【讨论】:

    • 感谢@LoicTheAztec,这正是我想要的。非常感谢您的回复。
    • 但是,使用 is_wc_endpoint_url('order-pay') 我有同样的问题,端点丢失在 URL 中,看起来像这样:myurl.com/结帐/
    【解决方案2】:

    $order = wc_get_order(get_query_var('order-pay'));

    【讨论】:

      猜你喜欢
      • 2021-06-12
      • 1970-01-01
      • 2015-03-19
      • 2019-01-27
      • 2014-11-18
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      相关资源
      最近更新 更多