Hello, @SquareMarket
This is the basic logic.
{% assign line_items=cart.items %}
//grab the whole cart
{% for line_item in line_items %}
//main loop. loop through the cart
{% for collection in line_item.product.collections %}
//now loop through the collections within each item
//some items belong to multiple collections
//(if they do it will count as different collections)
//now create a "previous item's collection" variable
//to check against if it doesn't exist
//and a flag (starts as true) to mark if it was the same as the last item.
{% if prev_collection == Nil %}
{% assign prev_collection = {{ collection.title }} %}
{% assign same_collection = true %}
{% endif %}
//now check if the current collection being checked
//is the same as the previous collection
{% if prev_collection != {{collection.title}} %}
{% assign same_collection = false %}
//if it's not, we mark the flag as false and pack it up.
//then we break out of the inner loop.
{% break %}
{% endif %}
//the current name is assigned to previous after checking
{% assign prev_collection = {{ collection.title }} %}
{% endfor %}
{% if same_collection == false %}
//we also break out of the outer loop.
{% break %}
{% endif %}
{% endfor %}
//now if the flag is false, no cart for you.
{% if same_collection ==true %}
// you get a cart.
{% endif %}
You might have to make some changes depending on weather you’ll store a global variable to block purchase or just use it to hide the cart button.
The comments aren’t liquid so you’ll have to edit those out. It’s easier to follow the logic without {% comment %} tags everywhere.