Home Forums WC Vendors Free Support Restrict client/Buyer to order from one vendor at a time

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.ย  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 26 posts - 1 through 26 (of 26 total)
  • Author
    Posts
  • #4230
    chauhanrushang
    Participant

    What I want to do is to restrict buyer from purchasing products from multiple vendors at once.

    Let say Vendor-1 has Product-1, Product-2 and Product-3
    Same way Vendor-2 has Product-4, Product-5 and Product-6

    Now what I want to do is restrict buyer from purchasing Products From vendor-1 and vendor-2 at same time. So buyer cannot buy Product-1 and product-4 togather.

    If buyer adds Product-1 and Product-2 from Vendor-1 Page, and then if he goes to Vendor-2 page the cart should be empty on Vendor-2 page. If he returns to vendor-1 Page the Cart should again show Product-1 and Product-2.

    I hope thats not confusing.

    Thanks,
    Rushang Chauhan

    #4231
    WC Vendors Support
    Participant

    That makes sense. You would want to write up some custom WooCommerce filter/action on the checkout page and cart page that would display an error and not allow checkout if the “author” of the products is not all the same. This is a WooCommerce modification, the WC Vendors docs wont really help you much on this one.

    http://docs.woothemes.com/document/hooks/
    http://docs.woothemes.com/wc-apidocs/hook-docs.html

    …is a list of all WooCommerce filters/actions. You’d have to identify which one works best for you, and go from there!

    There’s also a plugin that *sorta* does what you need, but not really, perhaps customizing this plugin might also help: https://wordpress.org/plugins/maximum-purchase-for-woocommerce/

    If you do write up a solution, we’d love it if you could post it back here and we can then add it to our KnowledgeBase in case other members are looking to do the same thing.

    #4234
    chauhanrushang
    Participant

    Hi Ben,

    Thanks for your quick response. I will see what I can do about that.
    =====

    I have one more question.
    –> Right now, when ever the buyer makes a purchase the admin has to “Receive the order” and then it shows up in the vendor dashboard. I want to give this capability to vendor for his order.

    So if purchase is made by buyer, then the order along with details will show up in vendor Dashboard , and then vendor will decide whether he wants to accept/process the order or reject it. Also correspondingly an email will be sent to Buyer, Admin(if order is rejected), and Vendor(if order is rejected) himself about the order status.

    #4248
    WC Vendors Support
    Participant

    When an order is marked Processing or Completed, commission is awarded to vendor and the Vendor Notification email is sent.

    There is no control for vendors to accept or reject orders. I’m not even sure that could be done, because buyers use payment gateways that take their money. You’d have to write in full refund provisions too, not an easy task and very specific to only your site. ๐Ÿ™

    #37201
    honey
    Participant

    Hello @chauhanrushang, did you have this problem resolved? if yes could you please share how. Thanks looking forward to your reply

    #38069
    honey
    Participant

    Finally, I found the solution after reading and reading…I will like to share this, probably it will be useful to someone. This solution actually removes the cart of previous vendor#1 and items of vendor#2 are added to cart .
    http://stackoverflow.com/questions/29092534/plugin-woocommerce-how-to-allow-add-to-cart-products-from-author

    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 ){$woocommerce->cart->empty_cart();}
    return $cart_item_data; }}

    #38070
    Anna
    Member

    Cool.
    Might I ask… what is the benefit of only allowing a customer to check out from one vendor’s shop at a time? (I’m not being a smart ass, I truly wish to know) ๐Ÿ™‚

    #38166
    honey
    Participant

    I am making use of shipping weight, that is what is accepted in my country. Each shippment has minimum charge per box. Since all sellers are not at the same point, the calculation without separating the cart will be wrong.

    #38168
    Anna
    Member

    Thanks, @honey – I wondered if it allowed a different way to configure shipping.

    #40703
    Hitesh
    Participant

    @honey please can you tell me on which file this code write.

    #40747
    honey
    Participant

    Do you mean file to include the code in? If yes, it is the function.php of your theme

    #43631
    Marc Bovet
    Participant

    Hi,
    the provided code was not working for me, I had to adapt it like this :

    $prodId = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_GET['add-to-cart'] );
    instead of
    $prodId = (int)$_POST[โ€œadd-to-cartโ€];

    I’ve also added a notice to inform the user.

    
    //Order only from 1 shop 
    //https://www.wcvendors.com/help/topic/restrict-clientbuyer-to-order-from-one-vendor-at-a-time/
    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
        $product_in_cart_vendor_id = get_post_field( 'post_author', $_product[0]->ID);
        $prodId = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_GET['add-to-cart'] );
        $product_added_vendor_id = get_post_field( 'post_author', $prodId );
    
        if( $product_in_cart_vendor_id !== $product_added_vendor_id ){$woocommerce->cart->empty_cart();wc_add_notice(  __("You can only order items from 1 shop !", "wcvendors"));}
        return $cart_item_data; } 
    } 
    

    cheers,

    Marc

    #48802
    Robert Vaughan
    Participant

    Not to dredge up an old thread but there are several significant reasons to only allow purchases from one shop. At one point I was running a marketplace where there were several shops running products through my site. Besides the nightmare of weight based shipping for shops located all across the globe and making sure those are setup correctly, customers wondering why they are paying so much in shipping because you can’t combine shipping from all the different locations is a customer service nightmare. Secondly, running reports and separating shipping and products from between the different shops can also be extremely time consuming. A feature to include, or exclude, shops from multiple shops carts would be a fantastic relief for me.

    #48806
    Anna
    Member

    In the future we will likely be moving to sub-order management in WC Vendors.
    For now, one of our next releases for WC Vendors Pro, v1.4.0 will at least have some more shipping options for the Vendor Shipping module included in Pro i.e. vendors can set a maximum $shipping fee per order regardless of items, free over $x amount, and more.
    You are correct- for proper weight based shipping the solution will not be feasibly until WC Vendors core is overhauled to create sub-orders and possibly allow for more shipping and other extensions to be possible.

    #48852
    Robert Vaughan
    Participant

    I’m not sure I understand what you mean with sub-order management.

    #60149
    Nexus
    Participant

    Hi,
    I know it is an old post and my question may never be seen but, while the Restrict code above works very well when switching vendors it fails to recognise product variations as being part of the same vendor’s product set. As a result, addition of a variable product wipes the cart clean.

    Has anyone had the same experience and is there any solution to this?

    Best,
    Nexus

    #60236
    Marc Bovet
    Participant

    Hi Nexus,

    Maybe something like this (untested) ?

    
    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;
    		break; //after 1st product we can stop the loop
        }
    
    	
        if(isset($_product[0]->ID)){ //getting first item from cart
    		if ($_product[0]->is_type('variable')){  //check if product is a variation
    
    			$available_variations = $product->get_available_variations();
    			foreach ($available_variations as $key => $value) 
    			{ 
    			  $product_id_in_cart= $value['variation_id'];
    			  break; //get first variation of product
    			}		
    		}	
    	    else //simple product
    		{
    		    $product_id_in_cart = $_product[0]->ID; 
    		}
    	    
    		$product_in_cart_vendor_id = get_post_field( 'post_author', $product_id_in_cart); //get vendor id from cart.
    		
    		$prodId = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_GET['add-to-cart'] );  //get last item added to cart
    		$product_added = wc_get_product( $productId ); //get product from ID
    		
    		if ($product_added->is_type('variable')){  //check if product is a variation
    
    			$available_variations = $product->get_available_variations();
    			foreach ($available_variations as $key => $value) 
    			{ 
    			  $product_id_added= $value['variation_id'];
    			  break; //get first variation of product
    			}		
    		}	
    	    else //simple product
    		{
    		    $product_id_added = $prodId; 
    		}		
    		
    		
    		$product_added_vendor_id = get_post_field( 'post_author', $product_id_added );
    
        if( $product_in_cart_vendor_id !== $product_added_vendor_id ){$woocommerce->cart->empty_cart();wc_add_notice(  __("You can only order items from 1 shop !", "wcvendors"));}
        return $cart_item_data; } 
    } 
    

    HTH

    #60287
    Nexus
    Participant

    Thanks for you efforts Marc.

    I tested the code but it doesn’t work. Tried to tweak it but I got nowhere. In its current form only one product can be added to the cart and subsequent additions are not possible; no matter whether it is a variable product or not.

    Also, the cart cannot be emptied by simply switching vendors. Addition of new product from a different vendor is not possible either.

    FYI, I’m using the wc_vendors free version.

    Best,
    Nexus

    #61751
    M
    Participant

    Emptying the cart is certainly not the way to go.

    #61773
    Nexus
    Participant

    Hi M,

    The purpose of this code is to restrict the customer to purchasing from one vendor only. Therefore, when a product from a secondary vendor is added to the cart, other cart items belonging to the initial vendor need to be removed.

    Honey’s July 24th code & Marc’s amendment of 27th of September do this very well.

    The only problem here is that addition of a variable product to the cart ALSO removes cart items; no matter the variable product is from the same vendor or not.

    This is the issue we were discussing lately.

    Best,
    Nexus

    #61944
    M
    Participant

    Hi Nexus @ALIB,
    By my comment, I meant that it’s a bad User Experience when you simply empty all of the cart after adding multiple products just because an incompatible one was added. You should rather show a message to the customer explaining the incompatibility and letting them take the decision about whether to purge the cart or proceed with it.

    As for Marc’s code, there is a typo in a variable’s name. I will let you find it. ๐Ÿ™‚

    Let me know if you can’t.

    Also, please let me know if you need some custom coding to provide a better UX.

    #64983
    Marc Bovet
    Participant

    @ALIB
    I’ll try to sort this out
    Marc

    #64987
    Marc Bovet
    Participant
    #66296
    oxandra panca
    Participant

    Hi Marc ,

    Thanks for code, have your got it completely ? like M said
    cz i also need it

    Thank you for your kindness

    #66298
    Marc Bovet
    Participant

    @OXANDRA

    not sure to understand by “have your got it completely ? like M said”….

    if emtying the cart is not compliant with your user experience, I let you improve my code.
    It’s working as expected on my website with an without variable products.

    Kind Regards,

    Marc

    #73266
    Thibault Voyeux
    Participant

    @marc-bovet
    I tried the code correction you gave, works perfectly except for 2 things:
    -Also have a problem with variable products (but I don’t really care, just added that issue in your notice.)
    -does’nt work if you add a product to cart directly from the miniature on shop page. This one could be a problem. Any idea? I’m ok to disable the “add to cart button on the miniature, but don’t know how to do it.
    Whatever, thanks for your code, solves one of the biggest issues of WC vendors free version, more appreciated than the per-product shipping solution (work in france, shipping is based on cart weight)

    PS: I also tried the 2 other codes you gave, gives me a blank screen if I add products from different sellers in my cart, but I don’t care. Thanks for your involvement in the community!

Viewing 26 posts - 1 through 26 (of 26 total)
  • The forum ‘WC Vendors Free Support’ is closed to new topics and replies.