Automatically display "SALE" badges on products that have discounted variants. This smart snippet checks all product variants and shows a badge when any variant has a compare_at_price higher than its price, creating urgency and highlighting discounts to boost conversions.
Checks all variants for discounts
Red badge with white text stands out
Creates urgency for discounted items
Perfectly sized for all devices
{% comment %} On Sale Badge Based on Price Shows sale badge when product variant is discounted Provided by XeeZone - www.xeezone.com/free-shopify-code-snippets-by-xeezone {% endcomment %} {% assign product_has_discount = false %} {% for variant in product.variants %} {% if variant.compare_at_price > variant.price %} {% assign product_has_discount = true %} {% endif %} {% endfor %} {% if product_has_discount %} <div class="sale-badge" style="position: absolute; top: 10px; left: 10px; background: #FF5252; color: white; padding: 5px 10px; border-radius: 3px; font-size: 12px; font-weight: bold; z-index: 1;"> SALE </div> {% endif %}
Go to Online Store → Themes → Edit code → Locate sections/product-template.liquid
Locate the product image container (look for product.media
or product.featured_image
)
Paste the snippet immediately after the product image container (within the same parent element)
In your product admin, set compare_at_price for variants to activate badges
Modify the CSS in the snippet to match your store's design
Pro Tip: Combine with the "Calculate Discount Percentage" snippet to show savings amounts next to the sale badge for even greater impact.