How to add Max Inventory, Limit Quantity Selector, and Callback Function on Brooklyn Theme

Highlighted
New Member
4 0 0

I've searched and found a couple of topics on this but no one explains the code or where to add it to the the theme.js file (which is a huge file).

I have products with variants and each variant has a different amount of inventory.  Right now a customer can select any amount of a certain variant even if I don't have that many in stock.  I need the quantity to check the inventory and not allow the customer to select more than I have in stock.  

I found a code but it only works for the first variant selected.  If a customer selects another variant, it doesn't change to that variants stock amount (which is why I need callback function).

Ideally, I would love for the customer to select a variant, it would show the total amount I have in stock under the quantity selector, then they can select how much they want without being able to surpass that amount.  

If someone could help, that would be great!  And I think it would help a number of others who probably want the same thing.  

Thanks in advance!

0 Likes
Highlighted
New Member
4 0 0

For info:  This code works on product-template.liquid

<div class="product-single__quantity">
<label for="Quantity" class="product-single__quantity-label js-quantity-selector">{{ 'products.product.quantity' | t }}</label>
<input type="number" hidden="hidden" id="Quantity" name="quantity" max="{{ product.selected_or_first_available_variant.inventory_quantity}}" value="1" min="1" class="js-quantity-selector">
</div>

It limits the amount of product you can order to the amount of inventory on the first variant selected.  If you select another variant, it doesn't change the amount you can order even if the new variant has less stock.  

I'm just wondering what code I need to input on theme.js.liquid so when you select a new variant, it automatically updates the amount of stock I have available for that variant.  

At least I assume that's what I need to do from the reading I've come across.  

 

0 Likes