Dawn Theme Help Needed - Show Inventory Quantities with Variants

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!

updateVariantInput called from onVariantChange dispatches a change event

https://github.com/Shopify/dawn/blob/a890eedb208454f4814523deb2b18136edb18596/assets/global.js#L633

selectCallback is meant for themes using shopifys js lib option_selection.js

Thanks, but I’m not quite sure what to do with this information.

I’ve been searching the forums for the code needed to make this work. But cannot find the exact code and where to put it to make the quantity change with the variations. There are many solutions for this, however, none of them work with the Dawn theme as described.

Can someone please provide the code and what templates to put it on to make this work?

1 Like

I’ve identified this as the code to change but the inventory_quantity isn’t in the json file so I’m not sure where you are supposed to get it from?

FYI to anyone using this theme and needing this customization. Shopify will install it for free with a paid plan. Just need to contact them to install.

2 Likes

Thanks!