How to limit customer purchases to one collection only?

Hello! I’m trying to find a way, either through an app or ideally through a simple addition of code, to prevent a customer from adding products from more than one collection to their cart. It must prevent the customer from adding an additional product to their cart if they already have a product in their cart from a different collection, and they must not be able to checkout.

For example, I have Collection A and Collection B. A customer can add as many products as they want from Collection A. However, as soon as they try to add a product from Collection B - if they still have a product(s) from Collection A in their cart - they are prevented from doing so and receive a message as to why. If they were to remove all product from Collection A from their cart, they could then add product from Collection B.

I’m not a developer but have a basic knowledge of adding code/script.

I will also note that my current review of apps that limit product totals etc do not offer this type of functionality.

Any help or recommendations is GREATLY APPRECIATED.

This isn’t simple because you need to edit several templates depending on theme and do tests to prevent a checkout you dont want that has mutually exclusive products.

You can contact me at paull.newton+shopifyforums@gmail.com with store name and details for pricing on this customization.

Loosely the starting code for product templates:

{% assign opposingcollection == "opposingcollectionname" %}
{% assign cart_collection_conflict == false %}
{% assign current_product_first_collection == product.collections.first %}
{% assign current_product_collections ==  product.collections | join:"" %}

{% for item in cart.items %}
 {% assign current_item_collections == item.collections | join:"" %}
 {% if item.collections.first == product.collections.first %}{% continue %}{% endif %}
 {% if current_item_collections contains opposingcollection  %}
  {% assign cart_collection_conflict == true %}
 {% endif %}
{% endfor %}

Then if there’s a conflict disable the add to cart and other buttons, or show a call to action.

Merchants needing product exclusion business logic can contact me at paull.newton+shopifyforums@gmail.com with store name and details for pricing.

Hi,

Does this use case still need extra dev or is it now part of Shopify native features?
Thanks in advance!

Also wondering the same thing.

Hello! Is there a solution on this topic?

hi,

We have implemented a similar solution.

Hope the logic can help, or else connect us to implement the same.

I noticed your question about collection-based restrictions. This is a mixed cart limit case.

In DC Order Limits, you can block specific product combinations, for example items from Collection A cannot be purchased with items from Collection B.

If you share which two collections you want to separate, I can outline the exact rule structure.

This is doable with an app, no theme edits. It’s not doable without an app, which is silly and a gap in Shopify. I’m Kory, I built CartGate. It does exactly this: “if one or more items from collection A are in the cart, don’t allow checkout if one or more items from collection B are also in the cart.”

It enforces server-side at checkout, so it holds on Shop Pay, Apple Pay and every other express path. I have stores like yours that were previously manually refunding dozens of orders a month. But after installing, not a single bad combination has gotten through.

It’s on Pro ($9/mo, 7-day trial). I’m happy to comp your first month and set it up with you.

It’s been a long time, so in all likelihood you’ve solved this, but still wanted to mention it just in case it’s still useful. App is called CartGate. :slight_smile: