2015-12-15 29 views
1

我需要通過woocommerce訂單ID或訂單號在wordpress中獲取post_id。如何從woocommerce的order_id中獲取post_id

global $woocommerce, $post; 

$order = new WC_Order($post->ID); 

//to escape # from order id 

$order_id = trim(str_replace('#', '', $order->get_order_number())); 

與此代碼我從訂單ID獲取訂單ID。我必須扭轉這一點,並從訂單ID獲取帖子ID。

+0

看看這個[url](http://wordpress.stackexchange.com/questions/97176/get-product-id-from-order-id-in-woocommerce) – Gunaseelan

回答

0

你確實意識到一個訂單可能包含1個或多個帖子ID權利?

$order = new WC_Order($order_id); 
$items = $order->get_items(); 

foreach ($items as $item) { 
    //$product_name = $item['name']; 
    //$product_id = $item['product_id']; // post id 
    //$product_variation_id = $item['variation_id']; 
}