• Resolved matthewnikolaeff

    (@matthewnikolaeff)


    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

Viewing 1 replies (of 1 total)
  • Hi @matthewnikolaeff, thanks for the query.

    In order to restrict the customers to buy from more than one vendor, you have to use this code :

    add_action('woocommerce_add_to_cart_validation','woocommerce_add_to_cart_validation',10,3);
    function woocommerce_add_to_cart_validation($passed, $product_id, $quantity){
        foreach (WC()->cart->get_cart() as $cart_key => $cart_item ){
            $cart_vendor = get_wcmp_product_vendors($cart_item['product_id']);
            $product_vendor = get_wcmp_product_vendors($product_id);
            if($cart_vendor && $product_vendor){
                if($cart_vendor->id != $product_vendor->id){
                    $passed = false;
                    wc_add_notice( __( 'Another vendor product is already in your cart.', 'woocommerce' ), 'error' );
                    return $passed;
                }
            }
        }
        return $passed;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Disable a feature’ is closed to new replies.