WooCommerce: Show Number Of Products Sold @ Product Page

WooCommerce database already stores the number of products sold for you.

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. Enjoy!

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

PHP Snippet: Show Total Number of Sales @ WooCommerce Single Product Page

/**
 * @snippet       Show Total Sales @ WooCommerce Single Product
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    Woo 3.7
 * @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 = $product->get_total_sales();
   if ( $units_sold ) echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}

Where to add this snippet?

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 files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

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 Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

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

  1. Bonjour Rodolfo,

    Great and useful snippet, merci!

    Now, I’m trying to figure out how to display those sales number aside the number of pageviews, within the product short description. (I already have the pageviews.)

    Like this :

    NAME OF THE PRODUCT
    Price

    By (name of the author) — x views — y downloads (or sales)

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Etc.

    Do you have any clue, amico?

    1. MV, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hey
    This gave me an error. I tried 1000 different code and no one works! Fck

    1. Hey, what error did you get?

  3. This currently works, but it’s a bad idea to use wordpress functions for woocommerce functionality – it will be deprecated in the next major release of woocommerce when other data store will be used.
    The correct code (for the future and for the current version) is:

    $units_sold = $product->get_total_sales();
    
    1. Thanks Robert!

    2. Since this will be face out soon, is it recommended to use it or any alternative for now? Thanks

      1. Snippet revised!

  4. Hello Rodolfo Melogli, The code working perfect. But problem is I want product sold show to next the reviews count.
    Here is screenshot: https://ibb.co/ZcKgzVZ
    Your help mean the world to me. Thank you!

    1. Hello Mey, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. in need of this feature urgently and stumbled upon your article. Helpful and trying it out now. Thanks for sharing

    1. Great!

  6. Hi,

    I want this to be printed under QuickView popup.

    What would be the hook to print under that?

    Thanks

    1. Hi Nancy, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  7. Good morning Rodolfo,
    Again, thank you very much for your codes, our woocommerce are unique thanks to your help!
    But I have a doubt, I want the units sold to appear after the categories (woocommerce_product_meta_end) and I have used this code, but it appears in two places, it appears below the price (which is the option with your original code) and I also get it below the categories (which is where I want to go). How can I fix it so that it does not come out below the price?
    Thank you!

    add_action( 'woocommerce_product_meta_end', 'bbloomer_product_sold_count', 5 );
    function bbloomer_product_sold_count() {
    global $product;
    $units_sold = get_post_meta( $product-&gt;get_id(), 'total_sales', true );
    if ( $units_sold ) echo '' . sprintf( __( '%s units sold.', 'woocommerce' ), $units_sold ) . '';
    }
    
    1. Hola Carlos! Silly question – did you delete the previous snippet (the one that was printing it below the price)?

  8. This snippet is great! I’m wondering if there is a way to only show sales over a certain date range. For example total_sales over the last 12 months or the last 7 days. From looking over the info available in the product_meta I couldn’t find a way to do that. Do you know if this is possible?

    Thank you!

    1. Hello A.J., thanks so much for your comment! Yes, this is definitely possible, but I’m afraid this is custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. hi, it is what i need, but i have a variable product.
    What i need is, that we just sell 100 pieces of the product. Under variations we add different quantity till that will reach the 100 pieces.
    each sale will count back from 100 till zero.
    You can support us with that? send a pm if you have time for this customizing.

    1. Hello Henk, thanks so much for your comment! Yes, this is possible – if you’d like to get a quote, feel free to contact me here

  10. I like this thanks

    Will add the woocommerce total downloads page to my blog

    1. Nice!

  11. 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 πŸ™‚

  12. 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

  13. 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

  14. Working for WooCommerce version: 3.4.4

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

    1. Nice πŸ™‚

  15. Hey Rodolfo,

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

    Thanks!

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

  16. 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?

    Thanks

    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
      
  17. 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

  18. 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

    Mark

    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.

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

    3. Hi guys,
      I have the same problem, i want to hide the “unit sold” , therefore, how can i do it using the code above and just changing a few code.

      Thank you.

  19. 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

  20. 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 πŸ™‚

  21. 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 πŸ™‚

  22. 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 πŸ™‚

  23. 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?

  24. 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 πŸ™‚

  25. Hi Rodolfo,

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

    Many thanks,

    Henry

    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

  26. 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

  27. 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

  28. Hi Rodolfo!

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

    Thxs!

    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

  29. 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.

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

  30. 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!

  31. 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!

  32. 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 πŸ™‚

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

    1. Ahah cheers for that Fanie!

  34. 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?

  35. hi

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

    thanks

    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!

  36. 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 πŸ™‚

      1. 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.

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

          1. Fantastic! Thank you!

  37. 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

  38. 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

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 *