Woocommerce - 在订单详细信息中显示总项目

Woocommerce - Show total items on order details

我正在尝试在结帐后显示在订单详情中购买的商品总数(数量)。

我将代码放在结帐页面上,效果很好:

<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>.

知道我如何将其添加到订单详细信息中吗?非常感谢。

您可以在模板中使用 2 个过滤器 woocommerce/templates/order/order-details.php,我认为使用过滤器比复制和编辑模板文件(如果可能)更好。

您可以使用woocommerce_order_items_tablewoocommerce_order_details_after_order_table,第一个站在主站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
}

希望对您有所帮助!