To use in Shopify to limit quantities of products ordered.
STEP 1: Upload the file jquery.limit.min.js to your Shopify theme assets on the Template Editor page.
STEP 2: Add the following code to your theme.liquid layout file before the closing body tag:
{{ 'jquery.limit.min.js' | asset_url | script_tag }}
<script>
Shopify.Cart.limit();
</script>Configuration parameters are all optional.
You pass an object to Shopify.Cart.limit().
That object is a hash of key/value pairs.
limitQuantity: a number, can be set to 0, 1, 2, 3 and up. Use 0 if you want to disable purchase. Default if not specified is 1.
limitPer: that on which the limit is imposed. Use ‘product’, ‘variant’ or ‘order’. Default if not specified is ‘product’.
limitProductHandles: an array of product handles. If you don’t set that parameter, the limit is imposed on every product in your shop. Default is an empty array.
limitSkipCartPage: a boolean. True if you want customer to skip the cart page and go directly to the checkout when he adds something to the cart. Default is false.
Shopify.Cart.limit(); will limit quantities purchased to 1 per product.
Example 1: Limiting to 3 items per product, so you can buy a max of 3 items of the same product, same or different variants of it:
{{ 'jquery.limit.min.js' | asset_url | script_tag }}
<script>
Shopify.Cart.limit({ limitQuantity: 3, limitPer: 'product' });
</script>Example 2: Limiting to 1 item per variant, so customer can buy 1 variant of a product and 1 other variant of same product:
{{ 'jquery.limit.min.js' | asset_url | script_tag }}
<script>
Shopify.Cart.limit({ limitQuantity: 1, limitPer: 'variant' });
</script>Example 3: You have a promo for a product with handle turtles-box and want to limit quantities to 4 per order just for that product:
{{ 'jquery.limit.min.js' | asset_url | script_tag }}
<script>
Shopify.Cart.limit({ limitQuantity: 4, limitPer: 'product', limitProductHandles: ['turtles-box'] });
</script>Example 4: You sell only one product in your shop, and customers will only want to buy 1 of it:
{{ 'jquery.limit.min.js' | asset_url | script_tag }}
<script>
Shopify.Cart.limit({ limitQuantity: 1, limitPer: 'order', limitSkipCartPage: true });
</script>