Must-Know Liquid Code Snippets for Shopify Customization

Must-Know Liquid Code Snippets for Shopify Customization

Shopify’s flexibility lies in its templating language Liquid. Instead of relying on bloated apps, mastering just a few snippets gives you the power to customize your store, improve speed, and control your user experience.

1. Show Product Inventory Only When Low

Let urgency drive action — but only when it matters.

				
					{% if product.available and product.inventory_quantity < 10 %}
  <p class="low-stock">Only {{ product.inventory_quantity }} left in stock!</p>
{% endif %}

				
			

2. Display Discounted Price & Savings

				
					{% if product.compare_at_price > product.price %}
  <span class="sale-price">{{ product.price | money }}</span>
  <span class="savings">Save {{ product.compare_at_price | minus: product.price | money }}</span>
{% endif %}

				
			

This boosts perceived value while minimizing pricing confusion.

3. Show “New” Badge for Recent Products

				
					{% assign now = 'now' | date: '%s' %}
{% assign published = product.published_at | date: '%s' %}
{% assign diff = now | minus: published %}

{% if diff < 604800 %}
  <span class="new-badge">New</span>
{% endif %}

				
			

Showcases new arrivals automatically without manual tagging.

“One line of Liquid can save you from installing one app and hours of debugging.”

Where to Place Snippets

  • Product loop? product-card-grid.liquid
  • PDP? product-template.liquid
  • Sitewide? Use global snippets and include with {% render 'snippet-name' %}

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Insights