Show discount amount on all products page

Solved
gwacht
Tourist
4 0 2

I am attempting to show the percentage discounted under the price. I have been successful in adding the discount percent on each individual product page using this code:

 

{% if product.compare_at_price_max > product.price %}Total Savings {{ product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max | money_without_currency | times: 100 | remove: '.0'}}%{% endif %}

 

My issue is I want it to show under all products too, not just when you select the product. Is this possible? I am using the debut theme, and I placed the above code in product-template.liquid. 

 

Thanks,

GW

Replies 16 (16)
EitanF
New Member
4 0 0

Hi, thanks so much for this solution.  I just tried it and although I copied the code you gave and the compare at price comes out, the discount comes out as "you save 0%" (in Spanish 'Te ahorras 0%). 

I'm using the Debut theme and the code I put was:

{% if product.compare_at_price_max > product.price %}You save {{ product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max | money_without_currency | times: 100 | remove: '.0'}}%{% endif %}

Here's a photo of the product page:

 

Screenshot 2020-07-20 18.13.56.png

 

Should I change something on the code, so that the 10% discount (which is the difference between the price and the compare at price) appears? 

Thank you very much,

 

Eitan

www.tindleer.com 

Ninthony
Shopify Partner
2247 339 900

Strange, that code should work. I literally just copied and pasted it into one of my developer themes and the discount percentage comes up. Would you mind if I requested access to your themes and took a look?

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
stylesbyalexis
New Member
2 0 0

can you help me with this code

Dixravi
New Member
6 0 0

Heym @BrianAtWork !

I've tried your method and I would not say that it did not work for me but not like the same way I was expecting.

See this screenshot: https://prnt.sc/wmaey6

I want something like this https://prnt.sc/wmafae

I am using the Debut theme in my store. Please help me out to create this kind of discount %.

Thanks in Advance

Ravi Dixit

alvinkonda
Shopify Partner
44 6 10

It seems the code provided it's not working with multiple currencies.

I have simplified the code and it seems the following works fine.

 

{% if product.compare_at_price > product.price and product.available %}
{{ product.compare_at_price
    | minus: product.price
    | times: 100.0
    | divided_by: product.compare_at_price
    | round
    | prepend: '-'
    | append: '%' }}
{% endif %}

 

 

KondaSoft.com - Premium Shopify themes that are simple to use, easy to customize, and awesome to your visitors.
WX99
New Member
1 0 0

Can i change the colour for the "Total Save %"?

If can please let me know what code should i added.

Thank so much 

ThatGuy_nemo
New Member
1 0 0

Hi there, I used the code provided and it worked great on my debut theme, except for the fact that the "price & sale" was duplicated under the original price. How do I remove the duplicate price and sale?

 

Screenshot 2021-11-10 at 21.53.04.png