2017-12-24 12 views
1

私は今すぐ私のWoocommerce電子メールテンプレートをカスタマイズしています。今は注文番号にアクセス権があります。私は注文の価格と数量を取得したいのですが、どのように把握することができませんでした。問題は、私は私がカスタマイズてる私の注文確認メールに表示できる数量と価格を取得できませんだと、私は現在のようwoocommerce 3.2.5電子メール通知でのみ注文番号で商品タイトルを表示

答えて

0

を実行しているされて

<?php 

    // Getting the order object "$order" 

$order = wc_get_order($order_id); 

// Getting the items in the order 

$order_items = $order->get_items(); 

// Iterating through each item in the order 

foreach ($order_items as $item_id => $item_data) { 

    // Get the item quantity, something is wrong here.. 

    $item_quantity = $order->get_item_meta($item_id, '_qty', true); 
    echo $item_quantity; 
    // Get the price, doesn't work either.. 
    $item_total = $order->get_item_meta($item_id, '_line_total', true) 


} 

?> 

あなたは、製品のタイトルをこのように得ることができ、$orderオブジェクトを持っている:

<?php 
    // Loop through order items 
    foreach($order->get_items() as $items){ 
     $product = $items->get_product(); // The product object 
     $product_name = $product->get_name(); // The product Name 
     $quantity = $items->get_quantity(); // The product Quantity 
     $line_total = $items->get_total(); // The line item total 

     // Display the product name 
     echo '<p>'.$product_name.'</p>'; 

     // Display the product quantity 
     echo '<p>'.$quantity.'</p>'; 

     // Display the product name 
     echo '<p>'.$line_total.'</p>'; 

     // Get the raw output to check 
     echo '<pre>'; print_r(echo $items->get_data()); '</pre>'; 
    } 
?> 

注文が多くの項目(大きく異なる商品名)を持つことができることを覚えておいてください。


関連trhread:Get Order items and WC_Order_Item_Product in Woocommerce 3

+0

こんにちは、私はちょうど[OK]を@WillSmith順序が唯一のサブスクリプション –

+0

である1オブジェクトが含まれていることを言ってwatmedビットを明確にするために、答えてくれてありがとうおかげスミス氏、Iサブディレクティブのオーダーをテストします。**質問:**どのテンプレートでカスタマイズを予定していますか?どのような電子メール通知ですか?私たちが推測できないすべての詳細を加えて、質問を更新してください。ありがとう – LoicTheAztec

+0

あなたのソリューションは完璧に機能し、ちょっとした調整が必要でした。しかし、私は上記のコードを使用して数量と製品価格を得ることができません –

関連する問題