Black Friday

A deal you can't resist! Get upto 20% OFF on this entire cyber week.

Claim Offer
03Day 15Hr 56Min 43Sec
Black Friday

How could one wc order only include one vendor products?

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!

Viewing 3 reply threads
  • Author
    Posts
    • #58558
      MOHO
      Participant

      I understand the customer could buy more than one vendor product in one wc order,

      But if i want the customer buy only one vendor products in one wc order?

      How could i make it?

      Attachments:
      You must be logged in to view attached files.
    • #58570
      WCFM Forum
      Member

      HI,

      You just have to add this code to your child theme’s functions.php –

      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

    • #58575
      MOHO
      Participant

      thanks it work now~

      That’s great!

    • #58590
      WCFM Forum
      Member

      Great .. you are welcome 🙂

Viewing 3 reply threads
  • The topic ‘How could one wc order only include one vendor products?’ is closed to new replies.