【问题标题】:How can I get the order ID from the order Key in WooCommerce?如何从 WooCommerce 中的订单密钥中获取订单 ID?
【发布时间】:2021-07-14 19:56:43
【问题描述】:

如何从 WooCommerce 中的订单 KEY 中检索订单 ID? (PHP代码)

例如

我有看起来像“wc_order_qkTc2RVyGtVil”的订单 KEY,我想获得看起来像“1950”的订单 ID。

背景: 我只得到一个包含订单密钥的链接。这就是为什么我不能使用命令 OBJECT 来获取 ID。

【问题讨论】:

    标签: php wordpress woocommerce endpoint orders


    【解决方案1】:

    在收到订单、支付订单和查看订单页面上,您可以从以下 URL 获取订单 ID:

    1)。在收到订单(谢谢)页面上:

    $order_id = absint( get_query_var('order-received') );
    

    2)。在订单支付页面:

    $order_id = absint( get_query_var('order-pay') );
    

    3)。在查看订单页面:

    $order_id = absint( get_query_var('view-order') );
    

    现在您可以使用wc_get_order_id_by_order_key() WooCommerce 功能,例如:

    $order_id = wc_get_order_id_by_order_key( $order_key );
    

    【讨论】:

    • 非常期待这个。 WC 文档中根本没有提到它。非常感谢
    猜你喜欢
    • 2020-05-08
    • 2020-08-26
    • 2019-09-08
    • 2014-03-05
    • 1970-01-01
    • 2017-07-02
    • 2017-08-26
    • 1970-01-01
    • 2017-11-11
    相关资源
    最近更新 更多