我的订单格式为 [domain]/checkout/order-received/[order_number]/key=[wc-order-key]
- 我如何获得 [wc- order-key]
?
到目前为止我已经完成了:
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id)
{
$order = new WC_Order( $order_id );
$myuser_id = (int)$order->user_id;
$user_info = get_userdata($myuser_id);
$items = $order->get_items();
foreach ($items as $item)
{
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
$product_description = get_post_meta($item['product_id'])->post_content
}
return $order_id;
}
最佳答案
如果我没理解错的话,你需要通过order_id获取order_key,对吗? 如果是这样,您可以只使用 WC_Order 属性:
$test_order = new WC_Order($order_id);
$test_order_key = $test_order->order_key;
已编辑
如indextwo所述,自 Woo 3.0 以来有新语法:
$test_order = wc_get_product($order_id);
$test_order_key = $test_order->get_order_key();
关于php - Woocommerce 获取订单 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669956/