layout | title | sidebar_title | description | nav | ||||
---|---|---|---|---|---|---|---|---|
default |
Limiting purchase quantities |
Limiting purchase quantities |
Learn about a workaround and an app for limiting purchases. |
|
_local/manual/products/inventory/limiting-purchase-quantities.md
- At the bottom of the theme.liquid file in the Layout folder, place the following at the bottom:
{% unless settings.limit == 'No limit' %}
<script>
var cartLimitSettings = {
strings: {
productHandle:'{{product.handle }}',
limitPer: '{{ settings.limit_per }}',
limitQuantity: {{ settings.limit_quantity }}{% if settings.limit == 'Enabled for products listed' %},
limitProductHandles: jQuery.trim("{{ settings.limit_product_handles }}").split(/[\s,;]+/){% endif %}{% if settings.limit_per == 'cart' and settings.limit_quantity == '1' %},
limitSkipCartPage: {% if settings.limit_skip_cart_page %}true{% else %}false{% endif %}{% endif %}
}
}
</script>
{% endunless %}
--
2) In your Assets folder, open and paste the following to the bottom of your theme.js
file:
Shopify.Cart.setProductHandle( cartLimitSettings.strings.productHandle );
Shopify.Cart.limit({
limitPer: cartLimitSettings.strings.limitPer,
limitQuantity: cartLimitSettings.strings.limitQuantity,
limitProductHandles: cartLimitSettings.strings.limitProductHandles,
limitSkipCartPage: cartLimitSettings.strings.limitSkipCartPage
});
--
3) At the bottom of the vendor.js
file, copy the code from here and paste it at the bottom
If you don't have a
vendor.js
file, use thetheme.js
file