Displaying inventory quantity in product page not working for variants. DEBUT THEME

Shopify Partner
42 1 2

Hi everyone! I have several limited products and I wanted to show the inventory quantity in the product pages by using product tags. The idea is for all the products tagged with 'last pieces' that has between 1 and 5 in stock, display "Last 4 available". I got it to work, here's picture.

 Captudre.JPG

The thing is, that the text won't change when selecting a new variant. If I select Variant A, it correctly displays the available stock, but when changing the variant, the text remains the same unless I refresh my browser, then it does show the correcto quantity. How can I 'refresh' this without having to reload the page again? 

Here's the code I added in product-template.liquid:

   <div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
        {% for tag in product.tags %}
        {% if tag contains 'ultimas piezas' and current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
		{% if current_variant.inventory_quantity <= 5 and current_variant.inventory_quantity != 1 %}
        <strong>¡Últimas {{current_variant.inventory_quantity}} piezas!</strong>
          {% else %} 
          {% if current_variant.inventory_quantity == 1 %}
          <strong>¡Última pieza!</strong>
          {% endif %}
        {% endif %}
        {% endif %}
        {% endfor %}
        </div>
0 Likes
Shopify Partner
94 5 8

How do you handle the variant change scenario? Pretty sure it must be some js in theme files.

0 Likes
Shopify Partner
42 1 2

To be honest, I'm not sure how my theme handle variants. I'm not a coder, just managed to do what I posted out of self taught coding haha so I'm kinda lost here!

0 Likes