Hello,
I’m currently working on building a new Shopify site, and I’m looking for some help with the code needed to show inventory quantities with variants with the Dawn theme. I found this article, and have been able to add the first part of the code on the main-product.liquid template. Show Inventory quantities on product pages
{% if product.variants.first.inventory_management == "shopify" and product.variants.first.inventory_quantity > 0 %}
We currently have {{ product.variants.first.inventory_quantity }} in stock.
{% endif %}
However, this only shows the quantity for the 1st variant, and does not change when a different variant is selected. Or if the 1st variant has 0 in stock, the “we currently have in stock” disappears completely.
The article I referenced above says Most Shopify themes will already have the selectCallback function. It is usually located towards the bottom of the theme.liquid file, or at the bottom of the product.liquid file. Look for this piece of code:
var selectCallback = function(variant, selector) {
I cannot locate this code in the theme.liquid file. The article references to follow this https://shopify.dev/themes/product-merchandising/variants but I’m really unsure of where to add any of that code to get this to work.
Would someone be able to explain in detail, what code I need to add and to which templates in the Dawn theme to get the quantities to change based on the variant selected?
Thank you in advance!