Keep customers from adding more to cart than what's available

Topic summary

A Shopify store owner encountered an issue where customers could add more items to their cart than available inventory, despite receiving a generic error message that didn’t specify the actual stock quantity.

Initial Solutions Provided:

  • Verify inventory tracking is enabled in Shopify Admin > Products > Inventory
  • Ensure “Continue selling when out of stock” is unchecked
  • Add an inventory quantity display block to the product template (available in Dawn theme)

Technical Fix (Dawn/Studio Themes):
A working solution involves editing the main-product.liquid file in the theme’s sections folder by adding max attributes to the quantity-input element:

max="{{ product.selected_or_first_available_variant.inventory_quantity }}"
data-max="{{ product.selected_or_first_available_variant.inventory_quantity }}"

Theme-Specific Variations:

  • Trade theme: Modify product-quantity.liquid (or quantity-input.liquid) with similar max attributes using variant.inventory_quantity
  • Balance theme: Additional code needed to prevent manual quantity editing via onChange handler

Ongoing Issues:
Some users report the solution doesn’t work correctly when:

  • Products have variants with different stock levels
  • Switching between variants, especially out-of-stock ones
  • Manual quantity editing still possible in certain themes
Summarized with AI on October 30. AI used: claude-sonnet-4-5-20250929.

Pls follow below steps to set limit to your quantity picker

  1. Open your theme code editor

  2. Find the file main-product.liquid in the sections folder and open it.

  3. Find the quantity-input code here

4.Copy below code and add the two attribute to the quantity-input box.

max="{{ product.selected_or_first_available_variant.inventory_quantity }}"
                        data-max="{{ product.selected_or_first_available_variant.inventory_quantity }}"

Hope this helps

4 Likes