On Shopify, I got this code to display available quantities in stock with a pretty visual effect on product page, but it don’t refresh on product with variants. I’m looking for a way to update stock availibility after variant changes, based on this code (without refreshing the page).
Refresh Stock Availability After Variant Changes
{% 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>
2
Answers
You’d need to hook into the variant update function in the JavaScript and then update that span with the current variants inventory amount.
Liquid is compiled on the server, so any updates to the page need to be made with JS
If you are using
Dawn
Theme you can easily do that by just using your code snippet in the correct place. As Dawn theme is updating HTML using ajax.Expected output
if any doubt please comment.