Discount % problem

Solved

Discount % problem

TrendBlend
Trailblazer
338 0 34

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

Schermafbeelding 2024-05-10 132906.png

But it has to stay when the product has a discount. Can someone please help me with this. Thanks in advance!

Accepted Solution (1)

Huptech-Web
Shopify Partner
1158 232 263

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 -%}

 

  • 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).



If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required

View solution in original post

Replies 2 (2)

Huptech-Web
Shopify Partner
1158 232 263

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 -%}

 

  • 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).



If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
TrendBlend
Trailblazer
338 0 34

Thankyou