How to get Order key for creating custom order return url in WooCommerce

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:34:16

There is 2 ways to get the order key:

1) From an instance of WC_Order object class using the method get_order_key(), this way:

// 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) 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;

The Order number is the Order ID in general…

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!