Skip to content

Instantly share code, notes, and snippets.

@ivandurst
Created July 1, 2016 22:44
Show Gist options
  • Save ivandurst/5ebe0aa25e044e4e76929138329b91f5 to your computer and use it in GitHub Desktop.
Save ivandurst/5ebe0aa25e044e4e76929138329b91f5 to your computer and use it in GitHub Desktop.
Shopify add a tag to a product that's on sale
{% comment %}
Add a tag to a product that's on sale. Add this in your template for displaying a product in a grid, for me it's called product-grid-item.liquid
{% endcomment %}
{% assign on_sale = false %}
{% if product.compare_at_price > product.price %}
{% assign on_sale = true %}
{% endif %}
{% comment %}
Work this into where the product image is displayed. I inlined the styles, but you can move them to a class if you want
{% endcomment %}
<a href="{{ product.url | within: collection }}" style="position: relative">
<img src="{{ product.featured_image.src | img_url: 'large_cropped' }}" alt="{{ product.featured_image.alt | escape }}">
{% if on_sale == true %}
<h4 style="position: absolute; top: 0px; right: 0; background: #B41106; padding: 6px; color: #fff;">Sale</h4>
{% endif %}
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment