I am trying to figure out a way to set a maximum quantity at the product level instead of on the individual variants.

The specific use case is selling tickets to events, where my client needs to be able to limit the maximum amount of tickets they can sell for a given event. However, each event can have multiple variants (full ticket, student ticket, etc.).

My current solution uses a custom number field on the product, and then I simply query all completed orders and count how many times the specific variant has been sold. But this seems very hacky and has a lot of potential edge cases.

I am somewhat new to Commerce so I might be missing something obvious, but I haven't been able to find anything in the documentation.

Any suggestions?

New contributor
Peter U is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Just to clarify, are you talking about the maximum that can be bought in a single transaction, or are you talking about the total stock? (i.e., the maximum that can be bought across the whole store?). Commerce has two different fields for managing those things, but as you have noticed, if a product is configured to have variants, both those fields are held at the variant level instead of the product level. Aug 4 at 16:05
  • @JamesSmith The latter. I want to limit the total stock across all variants for a given product. For example a product could be a ticket to an event, and I want to set a hard limit of 500 regardless of the combination of variants sold.
    – Peter U
    Aug 4 at 17:16
  • I'm fairly sure Commerce doesn't provide anything out of the box for your use case unfortunately. It'd make a good feature request though, or a custom plugin. Aug 5 at 10:13
  • @JamesSmith Thank you for taking the time. I solved this by creating a custom module that prevents lineitems from being added or sold if it exceeds the maximum allowed.
    – Peter U
    16 hours ago


Your Answer

Peter U is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.