Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/html/wpxss.com/application/wp-content/plugins/tweet-old-post-pro/vendor/codeinwp/themeisle-sdk/load.php on line 24

Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/html/wpxss.com/application/wp-content/plugins/tweet-old-post-pro/vendor/codeinwp/themeisle-sdk/load.php on line 29

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the pb-seo-friendly-images domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wpxss.com/application/wp-includes/functions.php on line 6260

Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/wpxss.com/application/wp-content/plugins/wp_glossary/includes/class-wpg-linkify.php on line 316
Display the total number of WooCommerce products - wpXSS

Deprecated: Function wp_get_loading_attr_default is deprecated since version 6.3.0! Use wp_get_loading_optimization_attributes() instead. in /var/www/html/wpxss.com/application/wp-includes/functions.php on line 6260
WooCommerce » Display the total number of WooCommerce products

Display the total number of WooCommerce products


Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/wpxss.com/application/wp-content/plugins/wp_glossary/includes/class-wpg-linkify.php on line 316

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