0

I need to find out the total quantity of added products in WordPress WooCommerce. How can I get it?

Dmitry Shulga
  • 588
  • 1
  • 6
  • 19
  • Possible duplicate of [WooCommerce - Getting total products count in the cart - not their quantity](http://stackoverflow.com/questions/31769985/woocommerce-getting-total-products-count-in-the-cart-not-their-quantity) – Prafulla Kumar Sahu Feb 03 '16 at 09:30

1 Answers1

0

By Following code you can get the number of product quantity in woo-commerce.

Add this function in your theme function.php file

function get_productcount() {
  $product_count = 0;

  // loop through all categories to collect the count.
   foreach (get_terms('product_cat') as $term)
      $product_count += $term->count;

   return $product_count;

}

Now from your any theme page you can call this function. In my example I added following line of code in header.php as,

<?php echo your_product_count() ?>  

Or In Other way you can directly add in your template

    $terms = get_terms( 'product_cat' );

foreach( $terms as $term ) 
{
    $product_count += $term->count;
     echo 'Product Category: '
    . $term->name
    . ' - Count: '
    . $term->count;
}  
echo "Total count:". $product_count;  
PHPExpert
  • 945
  • 5
  • 9