Restrict client/Buyer to order from one vendor/author at a time
-
The title tells what I want to achieve, I do have a small issue
Here is the code I have added to my function.php file
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' ); function woo_custom_add_to_cart( $cart_item_data ) { global $woocommerce; $items = $woocommerce->cart->get_cart(); //getting cart items $_product = array(); foreach($items as $item => $values) { $_product[] = $values['data']->post; } if(isset($_product[0]->ID)){ //getting first item from cart $prodId = (int)$_POST[“add-to-cart”]; $product_in_cart_vendor_id = get_post_field( 'post_author', $_product[0]->ID); $product_added_vendor_id = get_post_field( 'post_author', $prodId ); if( $product_in_cart_vendor_id == $product_added_vendor_id ) {return $cart_item_data;} else {wc_add_notice( 'Whoa hold up. You could only add items from one vendor at a time in your cart', 'error' );} } }
But the if else statement is not working, it’s adding the product to the cart and showing an error message too, please help me to resolve this issue. 🙂
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Restrict client/Buyer to order from one vendor/author at a time’ is closed to new replies.