<div class="product-card">
<a href="{{ product.url }}">
<img src="{{ product.featured_image | img_url: 'medium' }}" alt="{{ product.title }}">
{% render 'product-badge', product: product %}
<h3>{{ product.title }}</h3>
<p>{{ product.price | money }}</p>
</a>
</div>
{% if product.tags contains "bestseller" %}
<span class="badge badge-bestseller">Bestseller</span>
{% elsif product.tags contains "new" %}
<span class="badge badge-new">New Arrival</span>
{% elsif product.compare_at_price > product.price %}
<span class="badge badge-sale">Sale</span>
{% endif %}
This setup separates the product badge logic into its own snippet product-badge.liquid
, making it reusable across different sections like product listings and featured collections. The product-card.liquid
section renders the badge alongside the product info.
Martin Sojka, Maker of CodeSnips