How can I display out of stock text for product variants?

Hi everyone,

I’m trying to display “In stock” and “Out of stock” on my product page with custom liquid. So when a customer selects a variant inside the product, it checks if the variant is in stock or not, and shows the relevant text. I have tried this, but it doesn’t work, any ideas?

{% if variant.inventory_quantity < 1 %}

In stock

{% else %}

Out of stock

{% endif %}

Anyone knows what i do wrong?

Hi @Hannibal_Herman ,

Go to Online Store → Themes → Edit code → Sections → product-template.liquid and paste this code whereever you want to set.

{% if product.selected_or_first_available_variant.available == true %}
    

In Stock

{% else %}

Out of stock

{% endif %}

Hi Smalltask,

Thanks for the response, but it doesn’t work. ;(
You can still buy if it’s out of stock, so everyone is available. Is there a way so if there is min 1 in stock it says “in stock” and if there is 0 it says “Out of stock”?

try same thing but

{%- if variant.available == false %} -  out of stock {% endif %}

Doesn’t work ;/

you are most likely pasting the code into the wrong place then a good way to check is same code but put

testing

see where it shows up

I’m pasting the code correctly, just tried the

testing

and it shows up the right place.

But if i copy this code =
{%- if variant.available == false %} - out of stock {% endif %}

Nothing shows up ;/
My website is www.rios1931.dk

The problem might be in the way of implementation. You change your variant without page reload, because it’s dynamic and liquid code is not updated. It should be done with JavaScript, not Liquid.