Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › How could one wc order only include one vendor products?
- This topic has 3 replies, 2 voices, and was last updated 5 years, 8 months ago by WCFM Forum.
Viewing 3 reply threads
- AuthorPosts
- April 19, 2019 at 3:21 am #58558
- April 19, 2019 at 5:24 am #58570WCFM ForumMember
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
- April 19, 2019 at 6:43 am #58575MOHOParticipant
thanks it work now~
That’s great!
- April 19, 2019 at 8:36 am #58590WCFM ForumMember
Great .. you are welcome 🙂
- AuthorPosts
Viewing 3 reply threads
- The topic ‘How could one wc order only include one vendor products?’ is closed to new replies.