Trying to show the maximum discount on a product

Vernon_1
New Member
1 0 0

Hi there,

I'm trying to show the maximum discount available on a product while the user is on a collection page.

I've tried the below snippets to create a value that I can pull, however this is just causing an issue with saving - and it looks like the math filters are not being processed.

Could someone please point me in the right direction?

Thanks!

 

{% assign max_percent_off = 0 %}
{% for variant in product.variants %}
{% if variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price | round > max_percent_off %}
{% assign max_percent_off = variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price | round %}
{% endif %}
{% endfor %}

{% assign max_percent_off = 0 %}
{% for variant in product.variants %}
{% if {{ variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price | round }} > max_percent_off %}
{% assign max_percent_off = {{variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price}} | round %}
{% endif %}
{% endfor %}

 

 

 

0 Likes