Fel*_*oUl 2 php wordpress detail orders 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>.
知道我如何将其放在订单详细信息上吗?非常感谢。
您可以在模板中使用2个过滤器woocommerce/templates/order/order-details.php
,我认为最好使用过滤器,而不是复制并编辑模板文件(如果可能)。
您可以使用woocommerce_order_items_table
或woocommerce_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
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!