2016-06-07 135 views
2

我的訂單格式爲[domain]/checkout/order-received/[order_number]/key=[wc-order-key] - 如何獲得[wc-order-key]Woocommerce獲取訂單密鑰

到目前爲止,我已經做了:

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; 
} 

回答

6

如果我理解正確的,你需要的order_id得到order_key,是正確的嗎? 如果是這樣,您可以使用WC_Order屬性:

$test_order = new WC_Order($order_id); 
$test_order_key = $test_order->order_key;