Disable a feature

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 1 reply thread
  • Author
    Posts
    • #117776
      matfeinikolaev
      Participant

      Hello! My question is: You have a feature, allowing customers to buy products from different vendors in a single order. How can I disable this feature? I need a customer to do two different orders if he is buying from two vendors. Thank you

    • #118067

      Hello,

      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 );

      Thanks.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.