Show WooCommerce product count in theme

Couldn’t Google the solution so after some time a came up with the following solution:

// functions.php
function my_product_count() {
    $product_count = 0;

    // Get count for all product categories
    foreach (get_terms('product_cat') as $term)
        $product_count += $term->count;

    return $product_count;
<!-- header.php -->
<div class="counter">
    <span><?php echo my_product_count() ?><br>products</span>

Author: Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at Co-founded Blog at

7 thoughts on “Show WooCommerce product count in theme”

  1. thanks for your reply. I am using woocommerce and would like to have a plugin or widget that shows the number of products I have in my store but I can’t find anything like that…

  2. why not

    $count_posts = wp_count_posts(‘product’);

    $published_posts = $count_posts->publish;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s