The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Add a Custom “Sale” Badge to WooCommerce Products

Shared by Amit Dholiya · September 16, 2026 · @woocommerce_before_shop_loop_item_title

35 views
1 upvote
Back to Snippets

Want to make discounted products stand out in your WooCommerce store? You can automatically display a “Sale” badge on products that are currently on sale.

Steps

  1. Add the code below to your theme’s functions.php.
  2. Save the changes.
  3. Any product with a sale price will automatically show the badge.
/**
 * Add custom "Sale" badge to WooCommerce products
 */
function custom_woocommerce_sale_badge() {

    global $product;

    if ( ! $product || ! $product->is_on_sale() ) {
        return;
    }

    echo '<span class="custom-sale-badge">Sale</span>';
}

add_action(
    'woocommerce_before_shop_loop_item_title',
    'custom_woocommerce_sale_badge',
    5
);
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by