Skip to content

Instantly share code, notes, and snippets.

@drabbytux
Last active December 13, 2016 14:41
Show Gist options
  • Save drabbytux/1221e5b53620eff01c791bc1b4ef294c to your computer and use it in GitHub Desktop.
Save drabbytux/1221e5b53620eff01c791bc1b4ef294c to your computer and use it in GitHub Desktop.
Limiting purchase quantities
layout title sidebar_title description nav
default
Limiting purchase quantities
Limiting purchase quantities
Learn about a workaround and an app for limiting purchases.
group weight
Inventory
9

_local/manual/products/inventory/limiting-purchase-quantities.md

  1. 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 the theme.js file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment