# "Bestseller" Badge for Popular Products

> Labels products that have sold at least a set number of units with a "Bestseller" badge in shop listings and on the product page.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, badge, sales, social-proof
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-bestseller-badge/

## Code

```php
$wpide_bestseller_badge = function () {
    global $product;

    $min_sales = 50; // Units sold before the badge appears.

    if ( ! $product instanceof WC_Product || (int) $product->get_total_sales() < $min_sales ) {
        return;
    }

    echo '<span class="wpide-bestseller-badge" style="display:inline-block;margin:0 0 8px;padding:3px 10px;border-radius:3px;background:#dba617;color:#1e1e1e;font-size:12px;font-weight:600;text-transform:uppercase;">' . esc_html( 'Bestseller' ) . '</span>';
};

add_action( 'woocommerce_shop_loop_item_title', $wpide_bestseller_badge, 5 );
add_action( 'woocommerce_single_product_summary', $wpide_bestseller_badge, 4 );
```

## Notes

Change $min_sales to the number of units a product must sell to earn the badge.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Bestseller" Badge for Popular Products" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
