Limit purchases to only one collection?

New Member
2 0 0

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.

0 Likes
Shopify Partner
2569 133 430

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.

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes