How can I modify custom liquid code for inventory messages?

Hi all,

This has been driving me crazy for a while because I can’t figure it out.. and I’m sure it’s an easy line or two! Any help would be greatly appreciated.

Essentially on my product page I have custom code that displays inventory level. If Item Inventory is in stock, I have a message that displays the quantity. If Item Inventory isn’t in stock (though still trackable), I have a message that displays that it’s backordered. If Item Inventory isn’t tracked, I have it display a message that it’s a special order.

What I want to do however is split the code so inventory greater than XX (ie. >= 50) it displays one message (ie. We have lots in stock), and any inventory less than XX ( <= 49 to 1) it displays another message (We only have XX in stock).. and then of course the message for any inventory <= 0

This is what I currently have:

{% if product.variants.first.inventory_management == "shopify" %} {% if product.variants.first.inventory_quantity > 0 %} We have {{ product.variants.first.inventory_quantity }} in stock. {% else %} This product is currently on backorder. {% endif %} {% else %} This product is a Special Order. {% endif %}

Thanks in advance for your help!

Hi - try this:

{% if product.variants.first.inventory_management == “shopify” %}
{% if product.variants.first.inventory_quantity => 50 %}
We have loads in stock.
{% elsif product.variants.first.inventory_quantity > 0 and product.variants.first.inventory_quantity <= 49 %}
We have {{ product.variants.first.inventory_quantity }} in stock.
{% else %}
This product is currently on backorder.
{% endif %}
{% else %}
This product is a Special Order.
{% endif %}

@JohnWR That worked, thanks! I figured it had something to do with elsif, but I kept getting errors. I think my issue was that I wasn’t using the % after inventory quantity.

Thank you so much!

1 Like