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?
Let me know if you liked the post. That’s the only way I can improve. 🙂