DanWebb
11/30/2015 - 6:09 AM

Add a percentage sale to an item listing (ex: 20% off) based off it's compare at price and actual price

Add a percentage sale to an item listing (ex: 20% off) based off it's compare at price and actual price

{% 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 %}