All things Shopify and commerce
Hello I've added this code to my price.liquid from another shopify discussion so the standard sale badge shows % OFF and not the standard SALE badge.
{%- if show_badges -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
-{{ compare_at_price | minus: price | times: 100 | divided_by: compare_at_price }}% OFF
</span>
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
It works well but on the product page whenever a product does not have a discount it shows like this and it should not show
But it has to stay when the product has a discount. Can someone please help me with this. Thanks in advance!
Solved! Go to the solution
This is an accepted solution.
Hello @TrendBlend
You're employing Liquid code within a Shopify template to showcase a badge denoting a discount and another badge signifying that a product is sold out. Yet, you seek to conceal these badges when no discount is applied to the product. To accomplish this, you can tweak your Liquid code to exhibit the badges solely when a discount is present. Below is the adjusted code:
{%- if show_badges and compare_at_price > price -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
-{{ compare_at_price | minus: price | times: 100 | divided_by: compare_at_price }}% OFF
</span>
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
This is an accepted solution.
Hello @TrendBlend
You're employing Liquid code within a Shopify template to showcase a badge denoting a discount and another badge signifying that a product is sold out. Yet, you seek to conceal these badges when no discount is applied to the product. To accomplish this, you can tweak your Liquid code to exhibit the badges solely when a discount is present. Below is the adjusted code:
{%- if show_badges and compare_at_price > price -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
-{{ compare_at_price | minus: price | times: 100 | divided_by: compare_at_price }}% OFF
</span>
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
Thankyou
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025