How to only show variant quantity if less than 4?

Trailblazer
168 1 28

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
Astronaut
1082 147 272

Just use an if statement:

 

{% if variant.inventory_quantity < 4 %}
  <td style="text-align:center;">
    {{ variant.inventory_quantity }} in stock
  </td>
{% endif %}
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
1 Like
Trailblazer
168 1 28

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
Astronaut
1082 147 272

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 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
Trailblazer
168 1 28

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

0 Likes