How to only show variant quantity if less than 4?

Solved
Highlighted
Trailblazer
245 1 51

I've added this to my order form to show the quantity of each variant.

<td style="text-align:center;">
{{ variant.inventory_quantity }} in stock
</td>

However, I don't want to be displaying the full inventory. I'd just like it to display when there are less than 4. Is there anything I can add to this to accomplish that?

 

I'd really appreciate help with this!

Theme: Minimal

Url: LeilaCools.com

 

Screen Shot 2020-01-09 at 10.15.28 AM.png

0 Likes
Highlighted
Shopify Partner
1445 195 523

Just use an if statement:

 

{% if variant.inventory_quantity < 4 %}
  <td style="text-align:center;">
    {{ variant.inventory_quantity }} in stock
  </td>
{% endif %}
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
Highlighted
Trailblazer
245 1 51

That's awesome. Thank you @Ninthony !

 

I added  {% else %} and had a mostly empty column so I took out the <td> etc and placed it next to the product title and it looks great! Now I just need to figure out how to make the text red:)

 

{% if variant.inventory_quantity < 4 %}
{{ variant.inventory_quantity }} in stock

{% else %}

{% endif %}

 

Screen Shot 2020-01-09 at 11.03.09 AM.png

0 Likes
Highlighted
Shopify Partner
1445 195 523

This is an accepted solution.

for ease, you could put the line inside a div tag and add the styles inline:

 

{% if variant.inventory_quantity < 4 %}
<div style="color: red;">{{ variant.inventory_quantity }} in stock</div>
{% else %}
{% endif %}
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Highlighted
Trailblazer
245 1 51

Thank you but for some reason I got a liquid error when trying to add that. 

0 Likes
Highlighted
Trailblazer
245 1 51

This is what I ended up with. Great for my order form.

I would really like to use it on my product pages as well but I need it to show a separate tally for each variant. 

{% if variant.inventory_quantity < 4 %} Only

   {{ variant.inventory_quantity }} left

{% else %}

{% endif %}

0 Likes