2016-11-29 114 views
2

我試圖在結賬後顯示訂單詳細信息中所購買商品的總數(數量)。Woocommerce - 在訂單詳細信息中顯示訂單總數

我把結帳頁面上的代碼和工作的非常好:

<tr class="cart-subtotal"> <th><?php _e('Product Quantity', 'woocommerce'); ?></th> <td><?php global $woocommerce; ?><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></td> </tr>.

任何想法,我怎麼把這個訂單的詳細信息?非常感謝。

回答

4

您可以在模板woocommerce/templates/order/order-details.php中使用2個過濾器,我認爲最好使用過濾器而不是複製和編輯模板文件(如果可能的話)。

您可以使用woocommerce_order_items_tablewoocommerce_order_details_after_order_table,第一個站在主表中,第二個在後面。

add_filter('woocommerce_order_items_table', 'add_items_count_on_order_page'); 

function add_items_count_on_order_page($order){ 
    ?> 
    <tr class="cart-subtotal"> 
     <th><?php _e('Product Quantity', 'woocommerce'); ?></th> 
     <td><?php echo $order->get_item_count();?></td> 
    </tr> 
    <?php 
} 

希望它有幫助!

+0

工作!感謝您的幫助和解釋! –

+0

太棒了,不知道你以前是怎麼做的,但它可以節省很多時間! – Benoti

相關問題