Change Sale Badge to percentage saved on Dawn 11.0

Change Sale Badge to percentage saved on Dawn 11.0

NichlasBach
Visitor
2 0 0

I'm having issues trying to change the SALE badge on products to "save $xxx" which is the amount you save from the compare and real price instead of it just saying "SALE" and it can't just be in language because I have multiple products so it must be coded inside the code

I use Dawn theme 11.0


Replies 5 (5)

laddisahsi
Shopify Partner
385 38 41

Hi @NichlasBach 

1. Open 'product-price.liquid' and find {{ 'products.product.on_sale' | t }}, replace this with the code below:

 

 

{% assign percentage = 0 %}
{% for variant in product.variants %}
  {% assign saving = variant.compare_at_price | minus: variant.price | times: 100 | divided_by: variant.compare_at_price | round %}
  {% assign percentage = saving | at_least: percentage %}
{% endfor %} 
Save up to {{ percentage }}%

 

 

2. Click Save. 

 

If this solution is worked, then please Like this and Mark this as accepted solution!


Laddi

-Shopify website development, Theme & App Development
-Contact me: WhatsApp


-Email Me
-If this solution is worked, then please Like this and Mark this as accepted solution!
cbswco
Explorer
46 0 9

Hi @laddisahsi! It worked great for the pdp price but how can i use this same badge for the product card sale badge? I tried to do the same following your instructions but it only appears "Save 0%" instead of the real percentage. I would be very grateful y you can help me with this!

laddisahsi
Shopify Partner
385 38 41

Hi @cbswco 

This can be done using {{ product }} variable, for this have to check the code.

In  product listing page have run this code using product varibale.


If this solution is worked, then please Like this and Mark this as accepted solution!


Laddi



-Shopify website development, Theme & App Development
-Contact me: WhatsApp


-Email Me
-If this solution is worked, then please Like this and Mark this as accepted solution!
cbswco
Explorer
46 0 9

@laddisahsi thank you so much for your time answering. Could you be a little more specific with the instructions regarding code please 🙏 as i´m no programmer or so.

 

Thank you very much!

gr_trading
Shopify Partner
1919 145 199

Hi @NichlasBach ,

 

Please refer the below code to implement the same on product card.

 

{%- assign difference = card_product.compare_at_price | minus: card_product.price -%}
{%- assign float_difference = difference | times: 1.0 -%}
{%- assign discount_fraction = float_difference | divided_by: card_product.compare_at_price -%}
{%- assign discount_percentage = discount_fraction | times: 100 | round -%}
{{- discount_percentage }} OFF

 

To implement the same on product page in detail, kindly refer the video

For any custom development WhatsApp or connect at Email ID: [email protected] for quick consultation. | Shopify Free codes
To support Buy Me a Coffee