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 -%}
-{{ compare_at_price | minus: price | times: 100 | divided_by: compare_at_price }}% OFF
{{ 'products.product.sold_out' | t }}
{%- 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!
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 -%}
-{{ compare_at_price | minus: price | times: 100 | divided_by: compare_at_price }}% OFF
{{ 'products.product.sold_out' | t }}
{%- endif -%}
- The condition compare_at_price > price checks for the presence of a discount.
- The badges will only be visible if there’s a discount (compare_at_price > price evaluates to true).
1 Like