HOMEBlogTutorialsInstantly Boost Social Proof: Display WooCommerce Total Sales…

Instantly Boost Social Proof: Display WooCommerce Total Sales Count

WooCommerce Total Sales Count

You know that feeling when you walk past a restaurant with a massive line out the door? You immediately assume the food must be amazing. That is the psychological power of social proof. In the digital world, we don’t have physical lines, but we do have data. If you run an online store, learning how to display the WooCommerce Total Sales Count on your product pages is the digital equivalent of that busy restaurant queue.

When a new visitor lands on your site, they are looking for signals of trust. A simple badge stating “1,500+ Sold” can be the difference between a bounced visitor and a confident buyer. While there are heavy plugins that can achieve this, as developers, we know that leaner is always better.

In this guide, we are going to build a lightweight, custom solution to show the WooCommerce Total Sales Count. We will cover the code to retrieve the data, how to hook it into your single product templates, and how to style it so it looks professional. Whether you are selling digital downloads or physical goods, this metric is a key driver for conversion.

Why the WooCommerce Total Sales Count Matters

Before we dive into the PHP, let’s briefly touch on why this specific metric is so valuable. In the e-commerce ecosystem, silence is often mistaken for a lack of activity. If a product page looks static, customers might wonder if the store is even active.

Displaying the WooCommerce Total Sales Count serves three distinct purposes:

  • Validation: It confirms that others have spent money here safely.
  • Trend Identification: High numbers signal a “hot” item, triggering the Fear Of Missing Out (FOMO).
  • Transparency: It shows you aren’t afraid to share your data.

However, there is a catch. You only want to display the WooCommerce Total Sales Count when the numbers are impressive. Showing “2 Sold” might actually hurt your conversion rate. Therefore, our code will include logic to only display the count once it passes a specific threshold.


The Technical Approach: Get Post Meta

Under the hood, WooCommerce stores the total sales of a product as meta data. Specifically, it uses the key total_sales. This makes retrieving the data incredibly efficient because we don’t need to run complex SQL queries counting individual orders every time the page loads. We simply need to access the meta field associated with the product ID.

We will be using standard WordPress functions to fetch this data. If you are new to retrieving metadata, the WordPress Developer Resources page for get_post_meta is an excellent place to understand how we pull these specific fields from the database.


Step 1: The Core Function

First, we need to write a function that retrieves the sales count. We will use the prefix pnet_ to ensure our function names do not conflict with any other plugins or themes you might be using.

Add the following code to your theme’s functions.php file or a custom site-specific plugin. This code checks if the global product object is available, retrieves the sales count, and returns it.

PHP
/**
 * Helper function to get WooCommerce Total Sales Count
 * * @param int $product_id Optional. The product ID to check.
 * @return int The number of sales.
 */
function pnet_get_sales_count_number( $product_id = 0 ) {
    if ( ! $product_id ) {
        global $product;
        if ( ! is_object( $product ) ) {
            return 0;
        }
        $product_id = $product->get_id();
    }

    // Retrieve the total_sales meta data
    $count = get_post_meta( $product_id, 'total_sales', true );

    return (int) $count;
}

This simple utility function is the backbone of our strategy to display the WooCommerce Total Sales Count. By separating the logic of getting the number from the logic of displaying it, we keep our code modular.

You might also like:

Create Synced Pattern Programmatically: Easy 3-Step Guide (2026)

Need a scalable way to create synced pattern programmatically? Our simple guide solves deployment headaches instantly. Fix it now with...

Read more →


Step 2: Displaying the Count Automatically

Now that we have the number, we need to output it on the Single Product page. WooCommerce provides several “Action Hooks” that allow us to insert content at specific locations without modifying the template files directly.

A popular spot for the WooCommerce Total Sales Count is right below the price or near the “Add to Cart” button. We will use the woocommerce_single_product_summary hook for this.

WooCommerce Total Sales Count : WooCommerce Product Page Screenshot
WooCommerce Product Page Screenshot

Here is the code to inject the sales count. Note that we have added a conditional check: the count will only show if more than 5 items have been sold.

PHP
/**
 * Display the Sales Count on Single Product Page
 */
function pnet_display_sales_count_badge() {
    // Get the count using our helper function
    $sales_count = pnet_get_sales_count_number();

    // Configuration: Minimum sales required to show the badge
    $threshold = 5;

    // If sales are below threshold, do nothing
    if ( $sales_count < $threshold ) {
        return;
    }

    // Output the HTML
    echo '<div class="pnet-sales-count-wrapper">';
    echo '<span class="dashicons dashicons-chart-area"></span>'; 
    echo ' <strong>' . esc_html( $sales_count ) . '</strong> units sold!';
    echo '</div>';
}

// Hook into the single product summary
// Priority 11 usually places it just below the price (which is usually 10)
add_action( 'woocommerce_single_product_summary', 'pnet_display_sales_count_badge', 11 );

Understanding the Hook Priority

In the code above, you will notice the number 11 in the add_action function. In WooCommerce, the Product Price usually has a priority of 10. By setting our priority to 11, we ensure that the WooCommerce Total Sales Count appears immediately after the price. If you wanted it below the “Add to Cart” button, you would increase that number to roughly 31 or 32.


Step 3: Creating a Shortcode (Optional)

Sometimes, hooks aren’t enough. You might want to display the WooCommerce Total Sales Count inside a blog post about a product, or inside a custom Elementor or Divi builder layout.

For this, we can wrap our logic in a Shortcode.

PHP
/**
 * Shortcode to display sales count: [pnet_sales_count]
 */
function pnet_sales_shortcode( $atts ) {
    global $product;

    // Extract attributes (allow passing ID manually)
    $a = shortcode_atts( array(
        'id' => 0,
    ), $atts );

    $product_id = (int) $a['id'];

    // If no ID passed, try to get current global product
    if ( ! $product_id && is_object( $product ) ) {
        $product_id = $product->get_id();
    }

    if ( ! $product_id ) {
        return '';
    }

    $count = get_post_meta( $product_id, 'total_sales', true );

    // Return the number directly
    return (int) $count;
}
add_shortcode( 'pnet_sales_count', 'pnet_sales_shortcode' );

Now, you can type [pnet_sales_count] anywhere on your site to output the number. You could write a sentence in your product description like: “Join over [pnet_sales_count] happy customers!”

You might also like:

The Ultimate WordPress Settings API Tutorial: Create a Powerful Settings Page Easily

Learn step-by-step with this WordPress Settings API tutorial on how to create a powerful settings page using clean, secure, and...

Read more →


Step 4: Styling the Sales Badge

Raw text is functional, but it isn’t pretty. To make the WooCommerce Total Sales Count pop, we need some CSS. We want it to look like a trusted badge, perhaps using a distinct background color to catch the eye.

Add the following CSS to your Customizer (Appearance > Customize > Additional CSS) or your theme’s stylesheet.

CSS
.pnet-sales-count-wrapper {
    display: inline-block;
    background-color: #f0f4f8; /* Light modern gray/blue */
    color: #102a43; /* Dark Navy for contrast */
    padding: 8px 12px;
    border-radius: 4px;
    margin-top: 10px;
    margin-bottom: 10px;
    font-size: 0.9rem;
    border: 1px solid #d9e2ec;
}

.pnet-sales-count-wrapper .dashicons {
    color: #fca311; /* Orange accent color */
    vertical-align: middle;
    margin-right: 5px;
    font-size: 20px;
}

This styling uses a “Flat Modern” approach. The soft background separates the data from the rest of the description, while the orange icon draws the eye without being aggressive.

Tip: How To Change WooCommerce Add To Card Button in 2 Simple Steos


Troubleshooting Common Issues

Even with clean code, things can occasionally go wrong. Here are the most common reasons why your WooCommerce Total Sales Count might not be showing up.

  • Caching Plugins: If you are using plugins like WP Rocket or W3 Total Cache, the product page might be cached. If you make a sale, the number might not update immediately for visitors. This is usually fine for a sales counter (it doesn’t need to be live to the second), but if you are testing, make sure to clear your cache.
  • The “Zero” Issue: If you have just added a new product, the sales count meta key might not exist yet. Our code handles this by checking the threshold. If you want to verify it works, temporarily set the $threshold variable in the PHP code to 0.
  • Variable Products: Variable products can be tricky. The code provided above pulls the total sales for the parent product, which is usually what you want. It aggregates the sales of all variations (e.g., Small, Medium, Large) into one impressive WooCommerce Total Sales Count number.

Advanced Customization: Fake it ’til you Make it?

A controversial topic in development is “padding” these numbers. Some store owners ask to add a base number to the real sales count. For example, if you sold 5 items, but want it to show 105.

While I generally recommend transparency, you can easily modify the function pnet_get_sales_count_number to add a base integer to the return value. However, rely on the authentic WooCommerce Total Sales Count whenever possible. Customers are savvy, and authentic growth builds a more sustainable brand than inflated metrics.


Conclusion

Displaying the WooCommerce Total Sales Count is a low-effort, high-reward modification for any WordPress store. It leverages data you already have to build instant credibility with new visitors.

By using the pnet_ functions we created, you ensure your site remains lightweight and fast, avoiding the bloat of installing yet another plugin for such a simple feature. Remember to play with the CSS to match your brand’s specific color palette, and adjust the threshold to ensure you are only showing off numbers that you are proud of.

Do you have a specific placement on your product page where this badge converts best? Let me know in the comments below!

You might also like:

How To Allow Additional File Type Upload in WordPress

How to allow additional file type upload in WordPress Media library. Add custom or remove default file types in WordPress...

Read more →

Abhik

🚀 Full Stack WP Dev | ☕ Coffee Enthusiast | 🏍️ Biker | 📈 Trader
Hi, I’m Abhik. I’ve been coding since 2007, a journey that began when I outgrew Blogger and migrated to a robust self-hosted stack. That transition introduced me to WordPress, and I’ve been building professional solutions ever since.

Leave a comment