Limiting purchase quantities

As a shop-owner, you might want to offer deals but don't want a few customers to run away with all your stock. Or, it might not make sense for a customer to buy more than one item of a particular product, if it is a downloadable product, for example.

The following article will show you how to limit purchase quantities in your shop with fine-grained control. And it's fairly easy to implement. The walkthrough teaches you how to set maximum purchasable quantities.

Limiting quantities 1

Note

This solution will not work in the Lookbook or Venture themes.

If you're looking for the opposite to prevent small purchases, we recommend an app called Order Limits (Minmaxify) - available in our app store here. It actually handles both minimums and maximum purchases.

Before you begin

Depending on the theme you're using, you might need to disable a feature called Ajax on your cart page. To check if your theme uses Ajax, and to disable it:

  1. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  2. Find the theme you want to edit and click the Customize theme button for the theme.

  3. Click Cart Page.

  4. Find a checkbox that is named one of the following:

    • "Enable Ajaxify Cart"
    • "Stay on page when adding to cart"
    • "Cart type".
  5. Uncheck the box to disable the Ajax feature.

  6. Click Save.

    Limit quantity disable ajax

The name of the checkbox varies between themes depending on the language used by the theme developer.

Upload the file jquery.limit.min.js to your theme assets

Save the file jquery.limit.min.js to your desktop. You can download it from https://github.com/carolineschnapp/limiter by clicking the Clone or download button.

After you've downloaded the file, you can upload it:

  1. Unzip the file.

  2. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  3. Find the theme you want to edit, click the ... button, and then click Edit HTML/CSS.

  4. Upload the file jquery.limit.min.js as a new asset:

    Add new asset

Adding controls to your Customize theme page

While you're on the Edit HTML/CSS page, scroll all the way down in the left-hand side panel.

  1. Click Configs

  2. Click settings_schema.json

    Open settings html
  3. Scroll down to the bottom of your settings_schema.json file, and add this code before the last square bracket ] and after the last parentheses } - make sure to include that first comma , since you're modifying a JSON data structure.

    ,
        {
        "name": "Limiting Number of Products Purchased",
        "settings": [
          {
            "type": "select",
            "id": "limit",
            "label": "Limit the number of products purchased?",
            "options": [
              {
                "value": "No limit",
                "label": "No"
              },
              {
                "value": "Enabled for all products",
                "label": "Yes, and impose that limit on all products"
              },
              {
                "value": "Enabled for products listed",
                "label": "Yes, but only for the products listed below"
              }
            ],
            "default": "No limit"
          },
          {
            "type": "select",
            "id": "limit_quantity",
            "label": "If so, what limit do you want to impose?",
            "options": [
              {
                "value": "0",
                "label": "0"
              },
              {
                "value": "1",
                "label": "1"
              },
              {
                "value": "2",
                "label": "2"
              },
              {
                "value": "3",
                "label": "3"
              },
              {
                "value": "4",
                "label": "4"
              }
            ],
            "default": "1"
          },
          {
            "type": "select",
            "id": "limit_per",
            "options": [
              {
                "value": "variant",
                "label": "per variant"
              },
              {
                "value": "product",
                "label": "per product"
              },
              {
                "value": "order",
                "label": "items per order"
              }
            ],
            "default": "product"
          },
          {
            "type": "textarea",
            "id": "limit_product_handles",
            "label": "Enter your comma-separated product handles here:",
            "info": "(Leave blank if you are imposing your limit on all products.)"
          },
          {
            "type": "checkbox",
            "id": "limit_skip_cart_page",
            "label": "Skip the cart page if limit is 1 item per order?",
            "default": true
          }
        ]
      }
    
  4. Click to save your changes.

Important code to copy + paste

You will need to include the file jquery.limit.min.js in your theme.

  1. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  2. Find the theme you want to edit, click the ... button, and then click Edit HTML/CSS.

  3. Under Layouts, click theme.liquid to open it in the code editor

  4. You'll need to add some code before the closing </body> tag. That is near the bottom of the file - it will look something like this:

    Closing body tag

    And the code to add in is:

    
    {% unless settings.limit == 'No limit' %}
    {{ 'jquery.limit.min.js' | asset_url | script_tag }}
    <script>
    Shopify.Cart.setProductHandle('{{ product.handle }}');
    Shopify.Cart.limit( {
        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 %}
    
    
  5. Click Save.

Configure

Since you edited the settings_schema.json file earlier, the Limiter is now configurable in your Customize theme page. To configure the limiter:

  1. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  2. Find the theme you want to edit and click the Customize theme button for the theme.

  3. Look in the section Limiting Number of Products Purchased and follow the labels:

Limit purchase quatity x1

Scenario Examples

There are many different ways to configure the Limiter in your shop. Here's a look at five scenarios.

First scenario

You want to limit quantities purchased to 3 items per product, so that shoppers can buy a max of 3 items of the same product — same or different variants of it.

In your Customize theme section for limiting, use the following settings:

  • Limit the number of products purchased? – select Yes, and impose that limit on all
  • If so what limit do you want to impose? - select 3, and per product
Limit quantities scenario 1

Example: if you have an Awesome Tee available in Small, Medium and Large, shoppers will be able to purchase 2 X Small plus 1 X Medium of your Awesome Tee (or less).

Second scenario

You want to limit quantities purchased to 1 item per product, so that shoppers can buy a max of 1 item of any given product.

Example: you sell clothes that come in various sizes and styles. There can be up to 60 variants per product in your shop. You do not want the shopper to buy the same dress in Small Blue and Medium Red.

In your Customize theme section for limiting, use the following settings:

  • Limit the number of products purchased? – select Yes, and impose that limit on all
  • If so what limit do you want to impose? - select 1, and per product
Limit quantities scenario 2

Third scenario

You want to limit quantities purchased to 1 item per variant, so that shoppers can buy a max of 1 item of the same product variant.

In your Customize theme section for limiting, use the following settings:

  • Limit the number of products purchased? – select Yes, and impose that limit on all
  • If so what limit do you want to impose? - select 1, and per variant
Limit quantities scenario 3

Example: if you have an Awesome Book product available in Soft Cover and PDF download, shopper will be able to purchase both the Soft Cover and the PDF, but only one of each.

Fourth scenario

You have a “deal of the day” product, and its handle is “moon-palace-all-inclusive-golf-spa-resort-cancun-for-2-people”. You want to limit purchases of this deal to 1 per order. You don't want to limit purchases of any other product in your shop.

In your Customize theme section for limiting, use the following settings:

  • Limit the number of products purchased? – select Yes, and impose that limit on all
  • If so what limit do you want to impose? - select 1, and per product
  • In the Enter your comma-separated product handles here section, enter your product handle, for example, moon-palace-all-inclusive-golf-spa-resort-cancun-for-2-people
Limit quantities scenario 4

Fifth scenario

You want to limit products purchased to 3 per order. Shoppers can pick any 3 products they want in your store and check out with them — but not more. It could be 3 items of the same product.

In your Customize theme section for limiting, use the following settings:

  • Limit the number of products purchased? – select Yes, and impose that limit on all
  • If so what limit do you want to impose? - select 3, and items per order
Limit quantities scenario 5

Is there an app that makes this easier?

As mentioned above, the "Order Limits (Minmaxify)" app performs most of these functions and you can get it here.

Want to discuss this page?

Visit the Shopify Community

Ready to start selling online with Shopify?

Try it free