Last active
October 27, 2021 16:11
-
-
Save DanWebb/b922109a24f64ab57752 to your computer and use it in GitHub Desktop.
Add a percentage sale to an item listing (ex: 20% off) based off it's compare at price and actual price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} | |
Get a products sale percentage based off it's compare_at_price vs it's price | |
Example usage: | |
{% include 'sale_percentage' with product %} Off | |
Outputs for a product with a compare at price of £10 and a price of £5: | |
"50% Off" | |
{% endcomment %} | |
{% assign was_price = sale_percentage.compare_at_price %} | |
{% assign now_price = sale_percentage.price %} | |
{% if was_price > now_price %} | |
{{ was_price | minus: now_price | times: 100.0 | divided_by: was_price | round }} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment