Felipe Cnstzni Felipe Cnstzni - 1 year ago 85
PHP Question

Woocommerce - Show total items on order details

I'm trying to show the total (quantity) of items purchased on order details after the checkout.

I put the code on checkout page, and work's very well:

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

Any idea how i put this on order detail? Thanks so much.

Answer Source

You can use 2 filters in the template woocommerce/templates/order/order-details.php, I think it's better to use filter rather than copy and edit the template file (when it's possible).

You can use woocommerce_order_items_table or woocommerce_order_details_after_order_table, the first stands in the main table, the second one after.

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>

Hope it helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download