2017-03-16 79 views
1

我需要在結帳頁面上顯示每個供應商在產品前的運輸成本。 enter image description here如何在結帳頁面上顯示每件產品的運費? Woocommerce

我試着用

get_post_meta($cart_item['product_id'] , '_wcv_shipping_details', true); 

但這種回報與像空白值:

陣列([國家] => [國際] => [handling_fee] => [ national_qty_override] => [national_disable] => [national_free] => [international_qty_override] => [international_disable] => [international_free] =>)

+0

因爲它是返回一個** **陣列,在'get_post_meta的最後一個參數()'必須是**'FALSE' ** *(而不是'真')* ...也因爲它返回一個有空值的鍵陣列,這意味着沒有什麼是真正爲您的產品定義有關該送貨細節... – LoicTheAztec

回答

0

我認爲您試圖訪問訂單詳情頁面上的購物車對象。一旦訂單被放置,購物車對象將變空。您需要從訂單對象中獲取物品,然後獲取每件物品的運費。

// You can use this piece of code on thank you page (after order is placed) 

$order = new WC_Order($order_id); 

$order_item = $order->get_items(); 
foreach($order_item as $product) { 
    $prodct_name[] = $product['name']; 

    // here you will get product id and you can use that to get shipping details 
    get_post_meta($product['product_id'] , '_wcv_shipping_details', true); 
} 
+0

請告訴如何做? –

+0

爲感謝頁面添加代碼 –

相關問題