WooCommerce tracks the total number of units sold for each product. Displaying this number on the product page can serve as social proof and help increase conversions. Let’s see how to show the sold count next to the “Add to Cart” button in WooCommerce stores.
Keep in mind that displaying the sold count can work against you if a product has very few sales. We will add a threshold so the number only appears when sales exceed a minimum you define.
Display the Sold Count on the Product Page
Add the following code to the functions.php file of your child theme:
function sv_product_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold > 50 ) {
echo '<p class="units-sold">' . esc_html( $units_sold ) . ' sold</p>';
}
}
add_action( 'woocommerce_single_product_summary', 'sv_product_sold_count', 11 );Line 4 uses the WooCommerce CRUD method get_total_sales() to retrieve the total number of units sold. This is the recommended approach since WooCommerce 3.0 – it abstracts the data layer, so your code works regardless of how WooCommerce stores product data internally.
The threshold on line 6 (50 in this example) controls the minimum number of sales before the count is displayed. Adjust this number based on your store. Showing “3 sold” on a product page is unlikely to inspire confidence, while “500 sold” creates strong social proof.
Line 8 outputs the count wrapped in a paragraph with the class units-sold, which you can style with CSS. The esc_html() function ensures the output is properly escaped.
Why get_total_sales() Instead of get_post_meta()
Older tutorials use get_post_meta( $product->get_id(), 'total_sales', true ) to retrieve the sold count. While this still works, it directly queries the wp_postmeta table.
The get_total_sales() method is part of WooCommerce’s CRUD API. It reads from the product object’s data store, which means it will continue to work even if WooCommerce changes how it stores product data internally (similar to how HPOS changed order storage).
Always prefer WooCommerce’s product object methods over direct
get_post_meta()calls when working with product data. The CRUD API is the future-proof approach.
Changing the Display Location
The hook woocommerce_single_product_summary with priority 11 places the sold count right after the product title. You can change the position by using a different hook or adjusting the priority.
Common WooCommerce hooks for the product page include:
woocommerce_before_single_product_summary– before the product summary sectionwoocommerce_single_product_summary– within the summary, priority controls position relative to title, price, excerpt, and the add-to-cart buttonwoocommerce_after_single_product_summary– after the summary, near the tabs
For example, to display the count right after the price, use priority 15:
add_action( 'woocommerce_single_product_summary', 'sv_product_sold_count', 15 );Styling the Output
Add CSS to style the sold count. Here is a simple example:
.units-sold {
font-size: 14px;
color: #7a7a7a;
margin: 5px 0;
}You can also add an icon or badge styling to make the count more prominent, depending on your theme design.
FAQs
Common questions about displaying sold product counts in WooCommerce:
total_sales count?
total_sales count when an order status changes to "completed" or "processing". If an order is refunded or cancelled, the count is decremented accordingly.get_total_sales() returns the combined total of all variation sales for the parent product. You do not need to sum individual variations manually.get_post_meta() instead of get_total_sales()?
get_post_meta( $product->get_id(), 'total_sales', true ) still works. However, it bypasses the WooCommerce CRUD API and queries the database directly. The get_total_sales() method is the recommended approach because it is future-proof and works with any data store.woocommerce_after_shop_loop_item_title. The function logic stays the same - the global $product object is available in WooCommerce loops.total_sales value automatically when order statuses change. If you use a caching plugin, you may need to purge the product page cache for the updated count to appear immediately.Summary
Displaying the number of sold products on your WooCommerce product page is a simple and effective way to add social proof. Use $product->get_total_sales() to retrieve the count, apply a threshold to avoid showing low numbers, and hook into woocommerce_single_product_summary to control placement. A few lines of code can give your customers the confidence that others have already purchased the product.

