All things Shopify and commerce
I have the percentage off listed on my sales badges for products. My question is, how can I get that percentage to round up or down in 5's?
Example:
12% off will be listed as 10%
14.7% will list as 15%
My code currently is as follows:
{%- if show_badges -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{{ product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max | money_without_currency | times: 100 | round}}% OFF
</span>
Solved! Go to the solution
This is an accepted solution.
Hey @kathi8171
{%- if show_badges -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{%- assign discount = product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max -%}
{%- assign rounded_discount = discount | divided_by: 5 | round | times: 5 -%}
{{ rounded_discount }}% OFF
</span>
{%- endif -%}
This is an accepted solution.
Hey @kathi8171
{%- if show_badges -%}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{%- assign discount = product.compare_at_price_max | minus: product.price | times: 100.0 | divided_by: product.compare_at_price_max -%}
{%- assign rounded_discount = discount | divided_by: 5 | round | times: 5 -%}
{{ rounded_discount }}% OFF
</span>
{%- endif -%}
that worked!
Thank you!
Hi,
This has also worked for me, but only on the product page. Do you also have another code that works for the collection pages as well?
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024