Multivendor - 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', 'multivendor_cart_validate', 30, 2 );
function 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?
0 out of 0 found this helpful

Back to Help Center

Powered by Zendesk