There are two methods to display the number of products sold on WooCommerce stores: one using a plugin and the second by adding a code snippet to the functions.php file.

How to display product sold count with code snippet

Showing the number of products sold by adding a PHP code snippet to functions.php may seem quite overwhelming if you don’t have experience with coding. But it is a simple and risk-free process if you follow the steps correctly.

  • Open functions.php file

Open the WordPress admin dashboard and go to Appearance > Theme Editor to open the WordPress Theme Editor.

On this page, you can see the list files in your active theme under Template files on the right side of the page.

Scroll through the list of files to find the functions.php file. Once you see it, click on it to open it on the Text Editor in the middle of the page.

  • Copy the following code snippet

There are two code snippets below. The first one can be used to display the number of products sold on the single product page and the second code snippet can be used to display the count of products sold on the shop page.

Code snippet to show total sales on a single product page


// Show Total Sales on Product Page
add_action( 'woocommerce_single_product_summary', 'wp_product_sold_count', 11 );
function wp_product_sold_count() {
  global $product;
  $total_sold = $product->get_total_sales();
  if ( $total_sold ) {
   echo '<p>'. sprintf(__('Total Sold: %s','woocommerce'), $total_sold). '</p>';
  }
}

Code snippet to show total sales of each product on the shop page


// Show Total Sales on Product Loop Pages (Shop, Category, etc.)
add_action( 'woocommerce_after_shop_loop_item', 'shop_product_sold_count', 11 );
function shop_product_sold_count() {
  global $product;
  $total_sold = $product->get_total_sales();
  if ( $total_sold ) {
   echo '<p>' . sprintf(__('Total sold: %s','woocommerce'),$total_sold). '</p>';
  }
}

  • Add the code snippet to functions.php file

Add the code snippet to functions.php file

After copying the code snippet from above, go to the WordPress Theme Editor screen where you have the functions.php file opened.

Go to the end of the functions.php file and paste the code snippet at the end.

You can add both code snippets or anyone you wish depending on your requirements.

  • Customize the Total Sold text

If you want to change the Total Sold text something different, you can change it by making one small change in the code you added to the functions.php file.

If you look at the code snippet, you can see Total Sold at the bottom of both code snippets. You can change it to anything you wish. Please remember that you shouldn’t remove the single quote symbol before the word Total.

  • Save the changes

Once you make the changes, click on the Save file button to save the new changes you made in the function.php file. Now if you go to your online store, you can see the new element added to your WooCommerce store.

How to display product sold count with a plugin

If you are not comfortable with changing the code manually on your WooCommerce store, it is recommended to use a plugin to show the total number of products sold. In this blog, we use the WPB Show Product Sales Number for WooCommerce plugin by wpbean to achieve our goal.

  • Install the plugin

Open the WordPress admin dashboard of your WooCommerce store and go to Plugins > Add New.
In the search field, enter “WPB Show Product Sales Number for WooCommerce” and hit the enter key on your keyboard to start the search. Find the plugin by wpbean and install it. Once the installation complete, activate the plugin.

  • Configure the plugin

Once the plugin is activated, go to Settings > WooCommerce Show Sales from the left sidebar on the WordPress admin dashboard.

The settings are divided into two pages: General Settings and Style Settings.

Under the General Settings, you can manage the style and placement of the new element that shows the total sales.

On this page, you can also disable showing the count if the product sale is 0.

The settings are simple and self-explanatory. After changing the settings, click on the Save Changes button to save the changes.

On the Style Settings page, you can change the colour of the count and adjust the font size. Moreover, if you are familiar with CSS, you can also add CSS code to customize the style of the element the way you want.

After making changes on this page, don’t forget to click on the “Save Changes” button.

Summary

Showing the total number of products sold is a great way to persuade customers to make a purchase. It is social proof that shows the customer that other people also buy this product, so the product must be useful. Although WooCommerce doesn’t offer any default feature to display the count of products sold, it is not that difficult to configure. We hope that the two techniques we showed above will help you to display the number of products sold on WooCommerce stores.