Customers can only buy from one collection

Hello,

I am looking to figure out a way to restrict customers from buying items from more than one collection. I need to do this because it is a pickup and delivery service and a customer cannot pick items from two different “markets” which are being grouped under collection headings. If the item exists in both markets, they are added to both collections. If customers can pick from two different markets, it will be impossible to fulfill. How can I: a) add a restriction where adding to cart is Collection specific and b) show a message saying something like “Sorry, you can only add products from XYZ collection (“market”)” if customers try to add items from different markets that would violate the rule I am putting in place?

Thank you!

I would approach it like this:

  1. On all product pages, use Liquid code to get the contents of the cart

  2. If there is an item from another collection in the cart, then hide the add to cart button and replace with a message instead

This will help with identifying the code / cart object: https://shopify.dev/api/liquid/objects/cart

If you’d like a developer to handle this for you contact my team at speedboostr.com/contact. We make theme customizations like this every day.