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

Topic summary

Goal: cap how many units of a single product can be added to cart (e.g., stock 50 but allow max 20), ideally with a bulk-order message, without using an app.

Current state and pain points:

  • There’s no native Shopify setting to enforce per‑product max quantities. Multiple posts ask Shopify to add a backend solution.
  • Use cases: limit to 1 per customer (stop resellers/freight forwarders), free+shipping samples, and general per‑item caps.

Tried approaches and issues:

  • Theme code edit adding an HTML max attribute on the product quantity input works on desktop (with increment arrows) but fails on mobile where users can type higher numbers. It also doesn’t prevent multiple separate add‑to‑cart actions.
  • Cart drawer and cart page need identical validation; otherwise limits can be bypassed. Client‑side checks alone are insufficient.

Proposed workarounds (code-level):

  • Add a product metafield (Custom Data) like “Max Cart Quantity” and use Liquid to set max on quantity inputs in product and cart templates (e.g., main-product.liquid, main-cart-items.liquid). Also consider min/pattern/readonly and hiding buttons.
  • Logic to hide Add to Cart if item is already in cart or redirect to cart after adding.
  • Mentioned Liquid key quantity_rule.max exists, but no admin UI to set it.

Status: no official solution; app suggestions exist but many prefer a native feature. Open/ongoing.

Summarized with AI on December 14. AI used: gpt-5.

I am seriously regretting moving across from Square Space.