如何获取用于在 WooCommerce 中创建自定义订单返回 url 的订单键 [英] How to get Order key for creating custom order return url in WooCommerce
本文介绍了如何获取用于在 WooCommerce 中创建自定义订单返回 url 的订单键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我用来获取自定义订单返回 URL 的代码:
This is the code that I am using to get a custom Order return URL:
global $woocommerce;
$test_order = new WC_Order($order_id);
$test_order_key = $test_order->order_key;
$returnURL = site_url().'/checkout/order-received/7140/'.$test_order_key;
我需要的示例 URL 是:http://www.example.com/checkout/order-received/[order_number]/key=[wc-order-key]
The example URL that I need is: http://www.example.com/checkout/order-received/[order_number]/key=[wc-order-key]
我如何获得[wc-order-key]
?
How do I get [wc-order-key]
?
谢谢.
推荐答案
有2种方式获取订单键:
There is 2 ways to get the order key:
1) 从 WC_Order
对象类的实例使用 get_order_key()
,这样:
// Get an instance of the WC_Order object
$order_obj = WC_get_order($order_id);
// Get the order key
$order_key = $test_order->get_order_key();
$returnURL = site_url().'/checkout/order-received/'.$order_id.'/'.$order_key;
2) 使用 WordPress get_post_meta()
函数来自 $order_id
,这样:
2) Using the WordPress get_post_meta()
function from the $order_id
, this way:
// Get the order key
$order_key = get_post_meta( $order_id, '_order_key', true);
$returnURL = site_url().'/checkout/order-received/'.$order_id.'/'.$order_key;
订单号通常是订单 ID……
这篇关于如何获取用于在 WooCommerce 中创建自定义订单返回 url 的订单键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文