Update stock availability after variant change

Update stock availability after variant change

tembolino
Shopify Partner
1 0 1

Hi

I added a code to my product page which shows the items in stock. Problem is, it only shows the first variant of the product. If I change the color of the product for example, the stock value is not updated. The page needs to refresh to show the correct number. I found this code to force a refresh after variant selection:

<script> 
jQuery(function() {
$('.single-option-selector').on('change', function(){
setTimeout(function(){
if($('[name="id"]').val() != "{{ product.selected_or_first_available_variant.id }}"){
location.reload();
}
}, 1);
});
});
</script>

This doesn't seem to work, however.

Anyone knows a trick to force a page reload after variant selection?

 

I'm using "Empire" theme, sample page: https://www.tembo.ch/collections/1freizeit/products/flsk-cup-auslaufsicherer-kaffeegenuss-unterwegs?...

Thx

Reply 1 (1)

plfunkymusic
Excursionist
32 2 14

Did you manage to fix this problem?  I have the same issue with the Debut theme and color variants.  The stock for sizes is correct for the first color, but changing the color has no effect on size swatch.