Display number of items in cart together with total – WooCommerce

Just place this code in your child theme, usually it is the header.php file.

<?php
	
/*
Display number of items in cart and total
*/
	
global $woocommerce;

echo "Items in cart: ".sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
echo "<br />";
echo "Total: ".$woocommerce->cart->get_cart_total();
	
?>
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.00 out of 5)
Loading...Loading...

5 responses to Display number of items in cart together with total – WooCommerce

  1. Zeal says:

    How do I insert a custom message when the cart is empty?

    • Milan says:

      Hi Zeal,

      I’m not sure how would you like to format custom message or where do you want to place it.

      Perhaps code below could help:

      if($woocommerce->cart->get_cart_total() == '0'){
      	$custom_message = "This is my custom message";
      }else{
          $custom_message = $woocommerce->cart->get_cart_total();
      }
      echo "Total: ".$custom_message;
      

      Thanks.

  2. tinh says:

    thank you verry much.

  3. Daniel says:

    Thank you so much!!

  4. Cynthia Bartz says:

    This is perfect! Thanks so much.

    I modified it to include a link to the cart as well.

    My Version:
    `<?php
    global $woocommerce
    echo 'View Cart (‘ . sprintf(_n(‘%d’, $woocommerce->cart->cart_contents_count, ‘woothemes’), $woocommerce->cart->cart_contents_count) . ‘)

Leave a Reply

Your email address will not be published. Required fields are marked *

 

naro.vernell@mailxu.com trudeau_141 maysonmisha@mailxu.com