How can I limit the quantity of a single product in a cart?

9 0 34


I've looked thru the forum and can't seem to find what I'm trying to achieve (aside from the ubiquitous "use an app".

I'm looking for a simple solution to limit the amount of a single product that can be added to a shopping cart.

As an example, I have 50 units of a product in stock available to sell, but only want a max of 20 to be able to added to the cart.

One would think that it should be a core part of Shopify, give a request was make nearly 2 years ago on another thread.

I'm not looking for a lot of bells and whistles that come with some apps.

Ideally it would also create a message/popup that says for "bulk orders please contact us directly".

I'm using the Debut theme.


Come on Shopify, you say you support small businesses. If you talk the talk how about its time to walk the walk and get it done!





Replies 16 (16)

9 0 34

ok So I've eventually found this thread :


shopify limit quantity.jpg

and it has solved the problem at a basic level.

BTW the product-template liquid file is in "sections".

I'm not good at code and got it done, so its a pity Shopify wouldn't add this feature, as it should be simple.


thanks @Huanineupane 

4 0 26

For a simple feature like this Shopify should code it in the backend instead of store owners having to do the heavy lifting, please pull up your socks Shopify and make this a basic offering.

9 0 34

Unfortunately the above fix is only a "half " fix.


It works on laptop/desktop where arrows are used to add to the quantity. 

It does not work on mobile (where 90% of my customers are)

On mobile it is still possible to type in a higher quantity and successfully add to cart.


The further coding for this is beyond me, so if anyone has suggestions, they will be appreciated.


Thanks !

24 0 5

Change the type of the field from number to text. Did that work for you?

Shopify Partner
39 2 18

This will only stop someone from selecting a higher value when adding to cart all at once.  This doesnt stop them from going back to the item and adding another unit.

Happy to share knowledge of simple code changes. Click the link in my profile if you need help implementing.

12 0 13

My store is looking for this functionality as well. I am not super knowledgeable when it comes to coding, but I've tried a couple solutions I've come across on these forums and none of them quite work.

It's just mind-blowing to me that this still isn't a native feature in 2022. We already use about a dozen apps for relatively simple feature add-ons, and installing more just isn't sustainable or acceptable.  

We have a popular USA-exclusive product that we want to limit to 1 per customer to prevent resellers from buying them up and shipping them out of the country via freight forwarders (which is ANOTHER  problem for which Shopify's solution is "get an app"). We've tried adding language in the product description that says "Limit one per customer" but this message just gets ignored. And it's a pain for our customer service team to cancel these orders after the fact. 

Hoping Shopify finally gets around to adding this feature soon (or someone comes along with a good coding solution).

40 1 12

Hi! I'm trying to do the same exact thing. any chance you have found a solution to this? I'd be happy sharing knowledge so we can both make this work

Shopify Partner
264 20 32

Hello @chrisr408 


I understand you are not looking for app, but I don't think such solution is available by default in shopify at the moment.
I would suggest to check out our app for it

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Limit Qty Purchase

Need a developer?  Just visit MageComp website

Shopify Partner
2 0 4

This feature would be great!

5 0 1

We also would love this feature. We are planning on having a free + shipping test product that customers can try out to see if they like our product. Obviously we don't want to sell 30 units for free to a customer. It would be great if Shopify had an intrinsic feature to limit the quantity for certain products.

26 1 11

Yes it feels odd that after years of requests for this basic shop feature it is still not available in the core Shopify. While Multi-Language and other features might be complicated in core I do not think this one should be consuming much time from the core coder team. 

I really wonder how shopify will evolve regarding this and other features pretty standard in the main competitors but only available by subscriptions Apps in shopify. 

2 0 1

You can do this with Custom Data by adding a field to all your products called Max Cart Quantity, then edit your Liquid templates in the right place to set the max="" field on the Quantity <input HTML tag.



  1. Go to Settings -> Custom Data -> Products
  2. Click Add Definition
  3. Add a new field called Max Cart Quantity
  4. Take note of the Namespace and Key field. This will be important for the Theme editing.
  5. Select Type as Integer. Set Minimum Value to 1 so that you can't enter an negative quantity.
  6. Click Save

It should look like this once saved:

Screenshot 2023-12-03 at 11.39.25 PM.png

Note the custom field key of product.metafields.custom.max_cart_quantity.


Now lets edit your theme:

  1. Go to your theme and click on the three dots and click Edit Code.
  2. Find the .liquid files which contains the Quantity Input field. For the Dawn Theme this is in main-product.liquid and main-cart-items.liquid
  3. Look for the HTML which contains the quantity. This may looks something like





 Edit it to add a max field with a condition like:


{%- if product.selected_or_first_available_variant.product.metafields.custom.max_cart_quantity != null %}
max="{{ product.selected_or_first_available_variant.product.metafields.custom.max_cart_quantity }}"
{%- endif %}


Note the custom field key of product.metafields.custom.max_cart_quantity that was configured in our Custom Data for Products.


Now you can go edit any of your products and edit the Max Cart Quantity custom field that you made.

Screenshot 2023-12-03 at 11.48.29 PM.png

3 0 1

Presently, in that code there is already a max variable! in main-product.liquid:

{% if product.selected_or_first_available_variant.quantity_rule.max != null %}
data-max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
{% endif %}


So the code is there now!! But there is no place to set that max variable in the store or product. 🤔

24 0 5

I've worked on this for a bit.. and there are a few things that can be done to keep it simple:

1. Make sure the field on the "View Cart" page has a min, max, pattern, make it read only and hide the buttons if the line item of the cart contains a word (for example). Make sure that the sidebar cart has the exact same stuff in it.

2. Make sure that the product page or the button that you have implemented on any page is only there if the item isn't already in the cart. There's code floating around for this in this community.


And for now.. if you want to keep it simple..:

3. For those same product page or button.. make sure that it redirects to the cart (add hidden input field called return_to and give value of /cart. (or add this to the href string)


I'm trying to get some javascript together that would go around this last one.. because I have a page where the customer needs to stay on the page after the 'add to cart' click, but needs to check if the item is in the cart. It does find it in the cart, but can't figure out yet how to prevent to have it actually add to the cart...

24 0 5

Only issue that I have at this point is the cart drawer. Not sure how to check there for the name or price of the line item...

Shopify Partner
4 0 3

I am building my first online store and beginning to think I should have gone with another ecommerce platform as the basic functionality (quantity limits, purchaser email verification options, etc) are still not available after neraly 5 years. And to see the issue was 'solved' by subscribing to an app is absolute poor form Shopify. Reconsidering my initial choice...