Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › Product Vendors › Limit customer to buy from one vendor at a time
- This topic has 3 replies, 2 voices, and was last updated 5 years, 11 months ago by
WCFM Forum.
Viewing 3 reply threads
- AuthorPosts
- April 16, 2019 at 1:50 pm #58137
Luke
GuestSince in my country we still can’t use Stripe for payments (and split option).
We would like to limit customer to add products to cart from one vendor at a time.Is that possible?
- April 17, 2019 at 11:42 am #58286
WCFM Forum
MemberHI,
Please add this code snippet to your child theme’s functions.php for the purpose –
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 18, 2019 at 12:42 pm #58421
Luke
GuestThank You very much ! 🙂
- April 18, 2019 at 5:30 pm #58475
WCFM Forum
MemberYou are welcome 🙂
- AuthorPosts
Viewing 3 reply threads
- The topic ‘Limit customer to buy from one vendor at a time’ is closed to new replies.