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.

Hi @moharsh

Thanks for your feedback.

Pls follow below steps:

  1. At end of the quantity-input inputbox, add the code below
onChange="setStatus({{ product.selected_or_first_available_variant.inventory_quantity }})"

  1. And at the end of this file. Paste this code to this file.

Hope this helps!

Hi.

i tried this and it seems to somewhat work, but I can change the text inside the quantity selector once, and then it gets deactivated. Any help would be much appreciated:)

This does not seem to work correctly when I have variants with different stock… works good until I start changing variants, or change to a variant that is out of stock

Hi, I have the same issue, but I’m using the Savor theme. How can I prevent customers from adding more of one item to the cart that exceeds the quantity on hand, and how can I display the exact quantity on hand to the customer?