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!
PHP Snippet: Show Total Number of Sales @ WooCommerce Single Product Page
/**
* @snippet Show Total Sales @ WooCommerce Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible Woo 4.5
* @community https://businessbloomer.com/club/
*/
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>';
}
Hello, Rodolfo!
Thank you so much. I’ve looking for this for so long and works like a charm.
But I’d like to make two small modifications. The first one is the text in singular and plural. If there is 1 sale, the text should be “1 sale”. If there is more than 1, the text should be “% sales”.
And the second modification is, if there is no sale, shows that have one. If there is one, increase 2 sales to the number.
Is it possible, please?
Thanks again!
Hello Jessica, 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!
Hello sir,
Can I make it so that the number of product sales appears on the seller’s page (I use the WCFM Marketplace seller plugin) ?
Thanks a lot
Hello Yervand, 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!
Hi Rodolfo,
Thanks for the sharing!
may i know is there any ways to show the total sold result in quantitative class?
for example, 1-20 show <20, 21-50 show 100, etc.
Thanks
Hello Bess, yes that is possible with a bit of custom PHP
I had this code applied when I was using storefront, but my dev changed to elementor, and we cannot figure out how to display the sold count again.
Hi Jesse, unfortunately Elementor requires a different workaround. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It works with Elementor if you use a shortcode widget.
Hello.
Thanks so much for this snippet.
Please, My new products are suppose to show Total Sales: 0 but it does not show until There is at least 1 sale. IS there a way for me to show total sales even if it is 0?
Thank you
Yes! Try with:
Works well Rodolpho, but displays nothing for those products not sold yet. so better to add something like this to the snippet code:
Great idea, thanks!
Will this work with Variations, getting the number of products sold for each variation? If not is there something I can add to make it work with variations?
thank you
Hi Brent, 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!
can this done for grouped product type?
Hey Moo, 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!
Thank you so much Rodolfo, The code works very well on my site! Thank you, thank you, thank you!!!
Cool!
hello, can you confirm that it still works with latest woocommerce and wordpress ? thank you.
hello again, finally i was able to make it work on latest wordpress and woocommerce but it doesn’t show anything when no items are sold.
problem: my shop has been reinstalled and I do not have the real total of sales in database.
Can you easily change the code to show a minimum of 247 products sold please ?
thank you.
Yes you can change the code, but cheating on your figures is illegal
Hi Rodolfo,
Great work. Thanks a bunch. Needed this. Initially wasn’t working. Apparently was a positioning conflict(if i can call it that) with my page builder, since i styled my product page with it. So i checked your single product hooks page and changed woocommerce_single_product_summary to woocommerce_after_add_to_cart_form and it worked just fine. Is there more of the visual hooks guide for different woocommerce areas on the site?
Cool. Yes: https://www.businessbloomer.com/category/woocommerce-tips/visual-hook-series/
Can i get didn’t sell yet products list with name
Hi there, 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!
Hi,
Thanks for this great piece of work.
I want to multiply the result by 2 how could I do that?
Hi Andy:
Wonderful!
Many thanks
How can i display Number of sales on Shop page not Single product page..
please help
Hi there, 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!
hi i have a theme that shows the number of sold items, I don’t want it to show instead. how do i do this?
Thanks
Hi Dakid, 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!
Is it possible to do this but with a products total earned $ amount? So instead of the number of sales, the total money generated by those sales?
Thanks,
Hi Jacob, 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!
Hi Rodolfo
Works great, only, i am still setting up the site and testing.
Even though no products have been sold each product shows that their have been sales, random amounts.
Thanks
Marc
Did you place orders and cancelled them? Or did you import products from another website? Maybe “total sales” was not 0
Hello
Thank you so much for this,
Please I wish to enquire if is possible to generate a shortcode for each product total sales, so I can be able to display it on any page..
Please how possible is that??
https://www.businessbloomer.com/woocommerce-calculate-sales-by-product-id-shortcode/
Dear Rodolfo,
I´d like to show the Number of sold products only for one single product ID in my shop. Which line do I have to change in the code?
Does the snippet still wor with 3.9?
Best Regards
Ingo
https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/
Hi Rodolfo, many thanks for this snippet. Its working fine for me but when I delete all orders (shop reset) is still showing me past sales. woocommerce’s desktop says there are 0 sales for the product but the snippet counts deleted. Any ideas about this issue? Thanks in advance!
Hi Mario, total_sales does not update if you delete orders. Of course 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!
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,
I want to show number of customers who are ordering that product (this process is not yet processing or complete)?
Hi Shiv, 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!
Hi..
I get this error while trying to activate the snippet:
The snippet has been deactivated due to an error on line 12:
Cannot redeclare function bbloomer_product_sold_count.
That’s because somewhere in the same file or elsewhere you’re using my function already. Cannot declare it twice 🙂
Great thanks for sharing awesome script, Yes Obviously, It’s working on the product page. is there any way to show on the category/shop page?
Hello Anant, 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!
How do I get total order amount of individual product to make a donation type system?
Hey Santanu, 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!
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?
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!
Hey
This gave me an error. I tried 1000 different code and no one works! Fck
Hey, what error did you get?
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:
Thanks Robert!
Since this will be face out soon, is it recommended to use it or any alternative for now? Thanks
Snippet revised!
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!
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!
in need of this feature urgently and stumbled upon your article. Helpful and trying it out now. Thanks for sharing
Great!
Hi,
I want this to be printed under QuickView popup.
What would be the hook to print under that?
Thanks
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!
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!
Hola Carlos! Silly question – did you delete the previous snippet (the one that was printing it below the price)?
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!
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!
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.
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
I like this thanks
Will add the woocommerce total downloads page to my blog
Nice!
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?
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 🙂
It’s possible to display how many time the curent product was returned by customers?
Can you share that snippet with us?
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
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
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
Working for WooCommerce version: 3.4.4
Next step to for me to get this info below the SKU: 123456
Nice 🙂
Hey Rodolfo,
is there an easy way to add commas for these numbers? For example, 1,234 instead of 1234 sold units.
Thanks!
Hey Miroslav, thanks for your comment! Yes – this might help: https://codex.wordpress.org/Function_Reference/number_format_i18n
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
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:
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
This should do the trick Marco > https://businessbloomer.com/woocommerce-add-quantity-label-front-add-cart-button/
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.
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?
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.
I’m not sure Mark – I just tried my snippet again and it works fine 🙂
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.
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?
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
i am using latest woocommerce and my quantity sold just shows 1 or all products.
Hey there, thanks so much for your comment! I just tested it again on 3.2.6 and it works perfectly 🙂
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.
Thank you Sreenath! I just posted a revised snippet 🙂
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
Hey Dennis, thanks so much for your comment! I just improved the snippet so test it out and let me know 🙂
how can i place this in post not in my product page.
Hey Akquip, thanks for your comment! I have no idea – what’s the post about?
this has been really helpful, thank you!!
BTW, is there any way to modify the sold amount?
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 🙂
Hi Rodolfo,
Is there a similar way to report the total sales of all products within a category?
Many thanks,
Henry
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
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.
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
I want to show number of customers who are ordering that product (this process is not yet processing or complete)?
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
Hi Rodolfo!
Runs perfect..but is possible customize results with a date, for example:
sales after 21/05/2016…
Thxs!
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
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
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
hi! I followed your script but it’s not working when I updated to the latest version of Woocommerce.
Thanks for letting me know Mike. I’ll put this on my to-revise list!
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
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!
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!
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!
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 ?
Hey, thanks for your comment! This is weird as the snippet works on my dev site – what error do you get? Thanks 🙂
You have my Follow, LinkedIn, Facebook Like but most of all you have my respect and duel fellowship.
Ahah cheers for that Fanie!
Hi Rodolfo…. Thank you for your help… I wonder if you know how to do to see the total $ for each product.
Thanks Again.
Hey Adrian, thanks for your comment! You could possibly just multiply the number of products sold by the product price maybe?
hi
how to display the total sales for product who whas bought over 3 pieces per exemple?
thanks
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!
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 https://tcrascolorado.org/shop, but don’t see how they did that.
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 🙂
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.
Deb, take a look at snippet #3 🙂 I just added it to the blog! Thank you, R
Fantastic! Thank you!
Welcome 🙂
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
Mohammad, thanks for your comment! Take a look at WooCommerce official guide to rearrange tabs here. R
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
Thanks for this Fran!