Limit customer to buy from one vendor at a time

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums Product Vendors Limit customer to buy from one vendor at a time

Viewing 3 reply threads
  • Author
    Posts
    • #58137
      Luke
      Guest

      Since in my country we still can’t use Stripe for payments (and split option).
      We would like to limit customer to add products to cart from one vendor at a time.

      Is that possible?

    • #58286
      WCFM Forum
      Keymaster

      HI,

      Please add this code snippet to your child theme’s functions.php for the purpose –

      add_action( 'woocommerce_add_to_cart_validation', function( $is_allow, $product_id, $quantity ) {
      	$product = get_post( $product_id );
      	$product_author = $product->post_author;
      
      	//Iterating through each cart item
      	foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      		$cart_product_id = $cart_item['product_id'];
      		$cart_product = get_post( $cart_product_id );
      		$cart_product_author = $cart_product->post_author;
      		if( $cart_product_author != $product_author ) {
      			$is_allow = false;
      			break;
      		}
      	}
      
      	if( !$is_allow ){
      		// We display an error message
      		wc_clear_notices();
      		wc_add_notice( __( "Well, you already have some item in your cart. First checkout with those and then purchase other items!", "wcfm-ecogear" ), 'error' );
      	}
      	
      	return $is_allow;
      }, 50, 3 );

      Thank You

    • #58421
      Luke
      Guest

      Thank You very much ! 🙂

    • #58475
      WCFM Forum
      Keymaster

      You are welcome 🙂

Viewing 3 reply threads
  • The topic ‘Limit customer to buy from one vendor at a time’ is closed to new replies.