Sold Count Display

Keyboard shortcuts
  • JNext lesson
  • KPrevious lesson
  • /Search lessons
  • EscClear search

The Sold Count Display module shows “X sold” badges on products to build social proof. The count is based on actual completed and processing orders from your store.

Why Social Proof Matters

Shoppers trust products that other people have already bought. A “247 sold” badge signals demand and reduces purchase anxiety. This module makes that data visible without any manual effort.

Enabling the Module

  1. Go to Fluent Cart > GT Extensions.
  2. Toggle on Sold Count Display.
  3. Configure badge text and display settings.
  4. Click Save Settings.

Settings

  • Badge Text — Template for the badge. Default: {count} sold. The {count} placeholder is replaced with the actual number.
  • Minimum Count — Minimum sales required before the badge appears. Default: 1. Set to 10 or higher if you only want to show badges for popular products.
  • Show on Archive — Display the badge on product listing/archive pages. Default: Yes.
  • Show on Single — Display the badge on individual product pages. Default: Yes.

How It Works

The module hooks into fluent_cart/product/after_price (priority 10) to inject the badge HTML after the price display.

Data source:

The sold count comes from Fluent Cart’s OrderItem model. The query filters for orders with status completed or processing, groups results by product variation, and sums the quantities.

SELECT product_id, SUM(quantity) as total_sold
FROM order_items
WHERE order.status IN ('completed', 'processing')
GROUP BY product_id

The count reflects real sales data, not fake or inflated numbers.

Caching:

The module uses a static in-memory cache ($countCache) to store query results during a single page request. If the same product’s sold count is requested multiple times (e.g., in a loop), the database is only queried once.

There is no persistent cache (transient) by default. If you have a high-traffic store, you can filter the count to add your own caching layer.

Badge Display

The badge appears immediately after the price element with this HTML structure:

<span class="gtfc-sold-count">🔥 247 sold</span>

Default styling:

.gtfc-sold-count {
    display: inline-block;
    background: #f3f4f6;
    color: #374151;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 8px;
}

The badge uses a fire emoji prefix (🔥) followed by your configured text.

REST API

GET /wp-json/gt-extensions-fluentcart/v1/sold-count/{product_id}

Returns the sold count and pre-rendered badge HTML for a product.

{
    "product_id": 123,
    "sold_count": 247,
    "badge_html": "<span class=\"gtfc-sold-count\">🔥 247 sold</span>"
}

Requires manage_options capability.

Customization

Filter the sold count before display:

add_filter( 'gt_extensions_fluentcart/sold_count', function( $count, $product_id ) {
    // Add custom logic, external data sources, or caching
    return $count;
}, 10, 2 );

This filter receives the raw count and product ID. You can use it to:

  • Add persistent caching (set/get a transient)
  • Pull counts from external sources
  • Combine counts from multiple product IDs
  • Apply a multiplier or rounding