How to automatically calculate and display discount percentage?

Hi all,

See below example item. Is it possible to show % discount “automaticly calculated”? My website is only showing the information “KORTING” (Means SALE).

I would like to show as example: “10% KORTING”.

Thanks and have a nice day all!

You can do it within the liquid code. Find the code where place the KORTING text and replace it with this.

{% if product.compare_at_price > product.price  %}
{{ product.compare_at_price | divided_by: product.price | minus: 1 | time: 100 }}% Korting
{% endif %}

The above code will calculate the percent sale.

Hi @Be_Steven ,

Do you maybe have a idea in which template i should search? There are so many templates called “liquid” and in so many text is written “sale” and so on. I cant find the line you mean in the code.

Thanks and have a good day.

Hi,
@Be_Steven

I tried several edits, none of them worked. Can you help me out?

Last thing i tried i made picture of, didnt work.

I hope you can help me out :slightly_smiling_face:

Hi @frankmoi
sr for late.
If you are using the Dawn theme, you may find that from the bottom of this file snippets/product-card.liquid then change it become like this

So on frontend you will see the discount percent

If you are using another theme, I think you can find the file with the same keyword from snippets folder like: product grid item, product info, product card

Note: the code using need to change a bit

{% assign p_price = product_card_product.price | times: 1.0 %}
{{ product_card_product.compare_at_price | divided_by: p_price | minus: 1 | times: 100 | round }}%