Changing Quantity Selector into Drop Down List With Accurate Quantity

Hello,

I am currently using the Sense theme and am wondering if there is a way to change the quantity selector into a drop down list showing accurate quantity of all variants in stock. I do not want customers to be able to add more than what is available of a product, and I know that they will get an error message if they do with the current Shopify setup but I find that to be frustrating for the customer. I am not interested in using an app, I would much rather find a code for this.

Currently I have a drop down that shows a quantity of 1-10 for each listed variant, but is there a way for it to reflect each variants ACTUAL quantity? Here is the code I have:

<select name="quantity" id="quantity">
         {% for i in (1..10) %}
                  <option value="{{ i }}">{{ i }}</option>
          {% endfor %}         
</select>

Thank you

Hello @ubucci ,

To display the actual quantity of each variant in the dropdown list instead of a fixed range, you can modify the code as follows:


Hope this can help. Let us know if you need any further support.

Ali Reviews team

Hello, thank you for your reply, this is a step in the right direction, however now my drop down is only showing the total sum of the product. What I would like it to do for example is if I have 6 in stock I’d like a drop down showing the numbers 1-6

This is what I have, it creates a drop down showing quantity levels per variant. My only issue is it is not quantifying correctly and saying all variants have the same amount of quantity in stock, which is not true.