How to Show a Low Stock Warning on Shopify Product Pages -Horizon Theme (Liquid Snippet)


Creating urgency is one of the oldest and most effective tricks in e-commerce. You’ve probably seen stores display “Only 3 left!” under a product — and that subtle nudge can push hesitant buyers to take action fast.

In this tutorial, I’ll show you how to add a “Low Stock” warning banner to your Shopify product pages using a simple Liquid snippet.


💡 Why Add a Low Stock Warning?

  • ✅ Increases urgency → more conversions
  • 🧠 Helps communicate inventory scarcity
  • 📦 Useful when you don’t restock frequently

The Liquid Snippet

Here’s the code that checks the first variant’s inventory and shows a message if stock is less than 5:

{% if product.variants.first.inventory_quantity < 5 and product.variants.first.inventory_policy == 'deny' %}
  <div class="low-stock-warning" style="color: red; font-weight: bold; margin-top: 10px;">
    🔥 Hurry! Only {{ product.variants.first.inventory_quantity }} left in stock.
  </div>
{% endif %}

What it does:

  • Checks if the first variant’s quantity is less than 5
  • Ensures the store doesn’t allow overselling (inventory_policy == 'deny')
  • Displays a bold red message

Where to Place the Code

You can add the snippet inside:

/sections/main-product.liquid

Or, for older themes:

/templates/product.liquid

Recommended position: Just under your “Add to Cart” button or below the price tag.


Optional CSS Styling

To improve the appearance, add this CSS to your base.css, theme.css, or inline style tag:

.low-stock-warning {
  color: #e60000;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  margin-top: 10px;
}

Bonus: Support for Multiple Variants

The above code checks only the first variant. If your product has many variants, you can use JavaScript to dynamically update the low stock warning based on the selected variant.

Let me know in the comments if you want that version — I’ll post it next.


Conclusion

This simple UI tweak can boost your conversions by creating urgency. It’s a small detail that makes a big difference — especially during sales campaigns or when you’re dealing with limited imported stock.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.