While working on my Shopify store, I managed to find a code that displays the available quantities in stock with a visually appealing effect on the product page. However, I noticed that this code doesn't refresh when selecting different variants of the product. I am searching for a solution that will update the stock availability after variant changes without having to refresh the entire page.
Update Stock Availability Dynamically After Selecting Variants
{% assign current_variant = product.selected_or_first_available_variant %}
<div class="instock-pulse">
{% if current_variant.available %}
{% if current_variant.inventory_quantity > 0 %}<span class="icon--pulsing"></span>{{ current_variant.inventory_quantity }} pieces in stock
{% endif %}
{% endif %}
</div>