WooCommerce: Show Number Of Products Sold on Product Page

WooCommerce database stores the number of products sold.

Therefore, you may want to show such number on the product page, close to the Add To Cart button. As we’ve seen in my book Ecommerce and Beyond, showing the number of sales for each product can increase your sales conversion rate.

All you need is pasting the following code in your functions.php to show it in the product summary.

WooCommerce: Show Total Sales on the Single Product Page
WooCommerce: Show Total Sales on the Single Product Page

PHP Snippet: Show Total Sales @ WooCommerce Single Product Page

 * @snippet       Show Total Sales on Product Page
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=315
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.5.3
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_action( 'woocommerce_single_product_summary', 'bbloomer_product_sold_count', 11 );

function bbloomer_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
if ( $units_sold ) echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

66 thoughts on “WooCommerce: Show Number Of Products Sold on Product Page

  1. I like this thanks

    Will add the woocommerce total downloads page to my blog

    1. Nice!

  2. I am using this snippet and it works beautifully. I did notice though that the number of orders shown, the total sales, does not go down even if I trash an order on WooCommerce.

    For example, say there are 100 sales shown, but I go to Woocommerce -> Orders and I Trash an order and then empty trash, the sales shows stays at 100, instead of dropping to 99.

    Any idea why this is happening?

    1. Hey David, thanks for your comment! Product post meta does not change if you trash an order – that’s the problem. So you’d probably need a workaround. I’d run a WP Query that loops through each “published” order (and also only processing / completed) to give you the exact count. Hope this helps ๐Ÿ™‚

  3. It’s possible to display how many time the curent product was returned by customers?
    Can you share that snippet with us?

    1. Andrei, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  4. Hey,

    Great article. The code works perfectly as it is. I know nothing about php, but after a short Google search – I added >= 3 after if ( $units sold) to only display order counts when a product has been purchased at least 3 times.

    Is there a way to add a class name or id to either just the text or the just the count number? If there’s an easy enough way to do that and you care to share I’d be extremely grateful.

    Thank you for the post once again, not the first time I find useful code on your blog

    1. Hello Az – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  5. Working for WooCommerce version: 3.4.4

    Next step to for me to get this info below the SKU: 123456

    1. Nice ๐Ÿ™‚

  6. Hey Rodolfo,

    is there an easy way to add commas for these numbers? For example, 1,234 instead of 1234 sold units.


    1. Hey Miroslav, thanks for your comment! Yes – this might help: https://codex.wordpress.org/Function_Reference/number_format_i18n

  7. Bonjorno Rodolfo.

    I tried the snipped and it works for me. Very well described in the video. I just listed a product and normally by default it says;: Units Sold: 0 , yet is there a way to modify that for instance to say 20 and every other product to add on top?


    1. Hey there, thanks so much for your comment! Hoping that you’re not going to do anything illegal… you can simply add 20 to the PHP variable:

      $units_sold + 20
  8. Great tutorial
    I wanted to ad “Qty” in fro of the selection box where a user chooses the number of product to add to cart.
    I cannot for the life of me find the right hook or place top do this.
    Am I missing something obvious

  9. Hi Rodolfo

    After a recent upgrade, my product page started to show “Units Sold: XXX” (Units Sold 63). Another one of my WP sites now shows “XXX Sales” (134 Sales).

    I want to hide those.

    I added your snippet then edited the line $units_sold = get_post_meta( $product->get_id(), ‘total_sales’, false ); to “false” and that stopped the number from showing but now it says “Units Sold: array” (broken code).

    Is there another snippet or a way I could hide the entire words “Units Sold: XXX”?

    Thank you


    ps. Love your newsletter.

    1. Hey Mark, thanks so much for your comment! It’s not clear to me what you’re trying to do here… do you want to remove my snippet completely?

    2. Currently it is showing “Sales 688” indicating we sold 688 units. I do not want that displayed. I was hoping changing your snippet to False instead of True would hide the number of units sold.

    3. I’m not sure Mark – I just tried my snippet again and it works fine ๐Ÿ™‚

  10. So what if I want to show the amount of sales for a specific product on any page, say a sales page, I created myself?

    1. Hello Marcel, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  11. i am using latest woocommerce and my quantity sold just shows 1 or all products.

    1. Hey there, thanks so much for your comment! I just tested it again on 3.2.6 and it works perfectly ๐Ÿ™‚

  12. Hi,

    I used the code and below is the message on the product page

    Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/plugins/woocommerce/templates/single-product.php’), wc_get_template_part, load_template, require(‘/plugins/woocommerce/templates/content-single-product.php’), do_action(‘woocommerce_single_product_summary’), WP_Hook->do_action, WP_Hook->apply_filters, bbloomer_product_sold_count, WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /home/rsrnthr/public_html/wp-includes/functions.php on line 4139

    Units Sold: 40

    Please help me sort this.

    1. Thank you Sreenath! I just posted a revised snippet ๐Ÿ™‚

  13. Hello I add the code to the fiction in my child theme. It displayed unit sold; woocommerce.
    First it popup error on line line 9 or 10 saying error Syntex; (_()) so I removed the underscore _. After that it start to work but displayed Units Sold: woocommerce. Please what can I do to remove that woocommerce the display the amount sold or not to displayed if nothing has been sold. Thanks I love your tips on woocommerce

    1. Hey Dennis, thanks so much for your comment! I just improved the snippet so test it out and let me know ๐Ÿ™‚

  14. how can i place this in post not in my product page.

    1. Hey Akquip, thanks for your comment! I have no idea – what’s the post about?

  15. this has been really helpful, thank you!!

    BTW, is there any way to modify the sold amount?

    1. Hey Dan, thanks for your comment! Can you explain this a little bit better – I don’t get why you would want to do that ๐Ÿ™‚

  16. Hi Rodolfo,

    Is there a similar way to report the total sales of all products within a category?

    Many thanks,


    1. Henry, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  17. Hi Rudolfo. Code is working but i expect it to appear below the price. Instead it appears below the title.
    How can I make it appear below the price instead of above.

    1. Hey Gody, thanks for your comment. I recommend you study my “hook visual guide” for the single product page: https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/. Let me know

  18. I want to show number of customers who are ordering that product (this process is not yet processing or complete)?

    1. Thuc, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  19. Hi Rodolfo!

    Runs perfect..but is possible customize results with a date, for example:
    sales after 21/05/2016…


    1. Afredo, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  20. awesome stuff you have here

    i want to be able to ad a short code on a product page that displays the sales for that product from reason is that the people sells tshirts but they only ship once target is reached so it will look something like this “12/ 1200 sold” or “2188 sold, last day to order!

    We reached our goal! You can keep buying until the campaign ends!”
    i already have a timer that i add and got a shortcode for all products store wide sold but displaying that is a bit hectic as it looks like 198234/ sold haha

    1. Hey Izak, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Hopefully I will have time to create a snippet soon ๐Ÿ™‚ Thanks a lot for your understanding! ~R

    2. hi! I followed your script but it’s not working when I updated to the latest version of Woocommerce.

    3. Thanks for letting me know Mike. I’ll put this on my to-revise list!

  21. That was very helpful. I have a different situation here.

    I have already sold several products on eBay and hold a great reputation there. Now I am setting up this online store with WooCommerce and would like to show the number of products sold including the products sold on eBay. Is there a way I can enter the values of the products sold for each product and display them under the product.

    Truly appreciate your great support and valuable help.

    Best Regards,
    Syed H

    1. Thanks for your comment Syed! Yes, I would suggest using a “custom field” on the single product page, and then add that number to the WooCommerce sales. This should give you an idea: https://businessbloomer.com/woocommerce-show-product-custom-field-in-the-category-pages/. Let me know!

  22. Dear Rodolfo,

    Thank you for your major input in my PHP “insights”. I have a multi language webshop and I want to “echo” “Units sold:” in English, Dutch and German. Normally I am writing [EN] [DE] or [NL] in front of a piece of tekst to let wordpress know which language it is. In this snippet is doesnt work. Do you know how to make this snippet multi language proof?
    Thank you a lot!

    1. Thanks for your comment Rob! To make the string translatable, take a look at https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings. Hope it helps!

  23. HI, thank you for share us a great tutorial. i was searching this kind of tutorial but now i am happy with your tutorial.

    my issue is, when i put your codes in code snippets plugin , then my WordPress automatically logged out and codes doesn’t save and working .

    what should i need to do ?

    1. Hey, thanks for your comment! This is weird as the snippet works on my dev site – what error do you get? Thanks ๐Ÿ™‚

  24. You have my Follow, LinkedIn, Facebook Like but most of all you have my respect and duel fellowship.

    1. Ahah cheers for that Fanie!

  25. Hi Rodolfo…. Thank you for your help… I wonder if you know how to do to see the total $ for each product.

    Thanks Again.

    1. Hey Adrian, thanks for your comment! You could possibly just multiply the number of products sold by the product price maybe?

  26. hi

    how to display the total sales for product who whas bought over 3 pieces per exemple?


    1. Hey Kiamaru, thanks for your comment ๐Ÿ™‚ I’m afraid I’m not sure I fully understand your request… can you possibly explain it a little better? Thank you!

  27. I am creating a Woocommerce site for a non-profit I volunteer with. I was able to get the Total Sales (or in my case, Total Votes) to show up on the individual product page, but once voting starts, I want to be able to show how many votes each one has on the page for all the products. How can I do that? I’ve seen it done here http://tcrascolorado.org/shop, but don’t see how they did that.

    1. Hey Deb, thanks for your comment ๐Ÿ™‚ I just added another snippet that you can use on the “Loop Pages” instead. Simply change the hook to “woocommerce_after_shop_loop_item”. Hope this helps ๐Ÿ™‚

    2. Awesome! It did take away the Total Sales on the individual product page, but if I had to choose, I’d prefer it on the Shop page. Is there a snippet that will give Total Sales on both the Shop page AND the individual product page? When I used both codes above, it broke the page and I just got a blank page.

    3. Deb, take a look at snippet #3 ๐Ÿ™‚ I just added it to the blog! Thank you, R

    4. Fantastic! Thank you!

  28. Dear,
    Your tutorial is very awesome.
    I have an question; In product page, by default review tab open that is below product image. My question is, how can I make “product description” tab as default to open.

    Thanks in advance

    1. Mohammad, thanks for your comment! Take a look at WooCommerce official guide to rearrange tabs here. R

  29. Hi Rodolfo,

    Thanks for the guide. I came across your article a few months back when I was trying to display product sales for my store. The issue got a bit complicated because for fulfilment purposes I have different SKUs for different product packs (meaning 1 bottle SKU is different from 3 bottle SKU), so I’d have to sum sales.

    At the end I decided to count total customers instead, and I developed a plugin to count sales, customers and some more stats. Please do check the sales counter plugin, I named it “Social Proof”: https://shopitpress.com/plugins/sip-social-proof-woocommerce/. If you like it, please consider including it in the article.

    I love your WooCommerce tips, keep up the good work.

    Best regards,
    Fran Sanchez

    1. Thanks for this Fran!

Questions? Feedback? Support? Leave your Comment Now!
If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.