Prevent customers from ordering from more than 3 Vendors in Woocommerce

Viewed 676

I have found similar solutions to this, for example: "How to limit orders to one category". I have tried to modify the code but it's not specific enough.

In my case, each Vendor is defined by a product attribute value, 8 Terms at all. If the cart contains products from more than 3 different Terms, I need to set up a message that says "Sorry, you may only order from 3 different Vendors at a time".

This is what I'm using as a starting point:

add_action( 'woocommerce_add_to_cart', 'three_vendors' );
function three_vendors() {

  if ATTRIBUTE = SELECT A VENDOR; NUMBER OF TERMS > 3 {

   echo "Sorry! You can only order from 3 Vendors at a time.”;

   }
}

The middle line is me filling in the blanks using non-php language.

I am looking for a way to define the amount of variations in the cart. If this is not possible to do with Attributes, I am open to use Categories instead.

Does anyone know how to do this?

1 Answers
Related