Hi. How can we help?

How to buy products from a single vendor. No orders with different vendor products

You can allow to buy products from a single vendor. No orders with different vendor products with this custom code in functions.php of your theme:

if( function_exists( 'YITH_Vendors' ) ){
add_filter( 'woocommerce_add_to_cart_validation', 'yith_wcmv_multivendor_cart_validate', 30, 2 );

if( ! function_exists( 'yith_wcmv_multivendor_cart_validate' ) ){
function yith_wcmv_multivendor_cart_validate($valid, $product_id ){
$current_vendor = yith_get_vendor( $product_id, 'product' );
if ( ! $current_vendor->is_valid() ) {
return $valid;
}

$contents = WC()->cart->cart_contents;
if( !empty( $contents) ) {
foreach ( $contents as $item_key => $cart_item ) {
$vendor = yith_get_vendor( $cart_item['product_id'], 'product' );
if ( $vendor->is_valid() && $vendor->id != $current_vendor->id ) {
$message = 'You cannot purchase product from different vendors at the same time.';
wc_add_notice( $message, 'notice' );
return false;
}
}
}

return $valid;
}
}
}
Was this article helpful?
1 out of 1 found this helpful

Back to Help Center >