Display number of items in cart together with total – WooCommerce

June 9, 2013 in Blog, Code Snippets by

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();
	
?>

About Milan

The founder of Dessky, Milan has worked in all aspects of advanced web development, from building large commercialized e-commerce and social network systems to troubleshooting small wordpress blogs. His extensive skills cover virtually every area of web development. Milan works hard to implement tomorrow’s trends utilizing the cutting edge systems of today. He specializes in rich internet web application development and deployment, complex HTML5/CSS3 graphical design layouts, full blown framework-driven rich internet applications, and much more. Milan provides elegant solutions to complex problems encountered by businesses that use internet based services. Also he is the MSc of Computer Science.

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.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 *

 

stryskomariah@mailxu.com longton