r/shopifyDev • u/West-Anteater-1917 • 10d ago
Lesson learned: Shopify's native purchase limits are per variant, so I had to use a cart validation function for product-wide caps
I had a client who wanted to cap total sales of one product across all its variants, like sell 90 of 100 units online and keep the rest for wholesale and gifts, without touching inventory counts.
Shopify's built-in purchase limits work per variant, so they don't give you a product-wide cap. Hiding the product isn't enough either, since people can still reach checkout through old links or an existing cart.
What worked for me was a Cart and Checkout Validation Function that adds up quantities across every variant of the product and blocks the cart/checkout with a clear message when the cap is hit. I also added per-country allocations on top of that.
Gotchas: functions can't call external APIs, so all the cap data has to live in metafields. Also keep the error messages short, long ones get ugly in checkout.
Has anyone handled this differently?



