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.
Thank you to all of our customers!
- This topic has 25 replies, 11 voices, and was last updated 6 years, 8 months ago by Thibault Voyeux.
-
AuthorPosts
-
April 7, 2015 at 5:30 pm #4230chauhanrushangParticipant
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-6Now 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 ChauhanApril 7, 2015 at 5:47 pm #4231WC Vendors SupportParticipantThat 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.
April 8, 2015 at 1:50 am #4234chauhanrushangParticipantHi 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.
April 8, 2015 at 11:24 am #4248WC Vendors SupportParticipantWhen 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. ๐
July 14, 2016 at 4:20 pm #37201honeyParticipantHello @chauhanrushang, did you have this problem resolved? if yes could you please share how. Thanks looking forward to your reply
July 24, 2016 at 9:50 pm #38069honeyParticipantFinally, 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-authoradd_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; }}July 24, 2016 at 10:04 pm #38070AnnaMemberCool.
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) ๐July 25, 2016 at 6:37 pm #38166honeyParticipantI 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.
July 25, 2016 at 6:47 pm #38168August 22, 2016 at 9:24 am #40703August 22, 2016 at 3:33 pm #40747honeyParticipantDo you mean file to include the code in? If yes, it is the function.php of your theme
September 27, 2016 at 7:29 am #43631Marc BovetParticipantHi,
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
November 29, 2016 at 10:12 am #48802Robert VaughanParticipantNot 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.
November 29, 2016 at 10:35 am #48806AnnaMemberIn 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.November 29, 2016 at 1:49 pm #48852Robert VaughanParticipantI’m not sure I understand what you mean with sub-order management.
March 28, 2017 at 11:06 am #60149NexusParticipantHi,
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,
NexusMarch 29, 2017 at 4:06 am #60236Marc BovetParticipantHi 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
March 29, 2017 at 11:21 am #60287NexusParticipantThanks 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,
NexusApril 13, 2017 at 3:12 am #61751MParticipantEmptying the cart is certainly not the way to go.
April 13, 2017 at 6:29 am #61773NexusParticipantHi 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,
NexusApril 14, 2017 at 1:55 pm #61944MParticipantHi 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.
May 12, 2017 at 1:25 am #64983Marc BovetParticipant@ALIB
I’ll try to sort this out
MarcMay 12, 2017 at 3:23 am #64987Marc BovetParticipantMay 24, 2017 at 1:54 am #66296oxandra pancaParticipantHi Marc ,
Thanks for code, have your got it completely ? like M said
cz i also need itThank you for your kindness
May 24, 2017 at 3:27 am #66298Marc BovetParticipantnot 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
August 10, 2017 at 6:14 pm #73266Thibault VoyeuxParticipant@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!
-
AuthorPosts
- The forum ‘WC Vendors Free Support’ is closed to new topics and replies.