From fcd7276ce855a3643f85f05d1938bb1f6bfc37da Mon Sep 17 00:00:00 2001 From: soulchild Date: Wed, 15 Apr 2026 19:07:57 +0000 Subject: [PATCH] Use maximum discount percentage from variants Use maximum discount percentage from variants --- snippets/product-tile.liquid | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/snippets/product-tile.liquid b/snippets/product-tile.liquid index 7cead6e..366a339 100644 --- a/snippets/product-tile.liquid +++ b/snippets/product-tile.liquid @@ -265,9 +265,23 @@ {% assign text = sale_text | replace: "[percentage]", percentage | replace: ".0", "" %} {% elsif compare_at_price > price %} - {% assign tmp_percentage = price | times: 1.0 | divided_by: compare_at_price | times: 100 | floor %} + {% assign max_discount = 0 %} + + {% for variant in product.variants %} + {% if variant.compare_at_price > variant.price %} + {% assign discount = variant.compare_at_price | minus: variant.price %} + {% assign discount_percent = discount | times: 100.0 | divided_by: variant.compare_at_price | round %} + {% if discount_percent > max_discount %} + {% assign max_discount = discount_percent %} + {% endif %} + {% endif %} + {% endfor %} + + {% comment %} + {% assign tmp_percentage = tmp_price_max | times: 1.0 | divided_by: tmp_compare_at_price_max | times: 100 | floor %} {% assign percentage = 100.0 | minus: tmp_percentage | floor %} - {% assign text = sale_text | replace: "[percentage]", percentage | replace: ".0", "" %} + {% endcomment %} + {% assign text = sale_text | replace: "[percentage]", max_discount | replace: ".0", "" %} {% endif %} {%- liquid