【问题标题】:Woocommerce - Show total items on order detailsWoocommerce - 在订单详细信息中显示总项目
【发布时间】:2016-11-29 12:46:27
【问题描述】:

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

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

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

知道我是怎么把这个放在订单细节上的吗?非常感谢。

【问题讨论】:

    标签: php wordpress woocommerce orders


    【解决方案1】:

    您可以在模板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
    }
    

    希望对你有帮助!

    【讨论】:

    • 工作!!感谢您的帮助和解释!
    • 太好了,不知道你以前是怎么弄的,不过可以省不少时间!
    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 2023-03-30
    • 1970-01-01
    • 2022-01-15
    • 2017-01-17
    • 1970-01-01
    • 2019-08-31
    • 2018-07-31
    相关资源
    最近更新 更多