WooCommerce » Display the total number of WooCommerce products

Display the total number of WooCommerce products

To display the total number of WooCommerce products, you can use the following code snippet:

<?php
$products = wc_get_products(array(
    'limit' => -1
));

echo count($products);
?>

This code uses the wc_get_products() function to retrieve all published products, with no limit on the number of products returned. The count() function is then used to count the number of products returned and display the total.

To display only published products, add

'status' => 'publish',

in the array just before limit


You can place this code in your theme’s functions.php file, or create a new plugin file to add this functionality to your WooCommerce store.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended