Wednesday, 15 February 2012

php - Plugin: Woocommerce > How to allow add to cart products from author -


Background: I am working on the creation of a market based on the woocommerce plugin. Therefore, when each vendor has different conditions like shipping charges, minimum amount, etc., then I would like to allow the customers to go to the cart according to the orders of only one vendor.

Work done so far: I can compare the cart item vendor with the current vendor. It should be noted that the code below is not working properly if W3 Total Cache is enabled

  function check_cart_by_vendor () {global $ woocommerce; $ Items = $ woocommerce- & gt; Cart- & gt; Get_cart (); $ _product = array (); Foreign currency (item item $> $ $ as values ​​$ $) {$ _product [] = $ value ['data'] - & gt; Post; } If (isset ($ _product [0] -> ID)) {$ product_in_cart_vendor_id = get_post_field ('post_author', $ _product [0] - & gt; ID); Global $ post; $ Vendor_id = get_the_author_meta ('id'); If ($ vendor_id == $ product_in_cart_vendor_id) {resonant "same seller";} and {"another seller" resonates;}} and {resonant "same seller";}}  

< Strong> What do I need for the scenario: A customer was added to the cart products from a seller, then he chose another vendor and was again added to the cart product from another vendor when he added the products from the 2nd vendor Want your cart to automatically get 1 vendor Removed from Products

Question: How to implement scenaio above?

I have understood it from my own code below

  function woo_custom_add_to_cart ($ Cart_item_data) {global $ woocommerce; $ Items = $ woocommerce- & gt; Cart- & gt; Get_cart (); // cart item is getting $ _product = array (); Foreign currency (item item $> $ $ as values ​​$ $) {$ _product [] = $ value ['data'] - & gt; Post; } If (isset ($ _products [0] -> ID)) {item received before the cart $ prodId = (int) $ _ POST ["add-to-cart"]; $ Product_in_cart_vendor_id = get_post_field ('post_author', $ _product [0] - & gt; ID); $ Product_added_vendor_id = get_post_field ('post_author', $ prodId); If ($ product_in_cart_vendor_id! == $ product_added_vendor_id) {$ woocommerce-> Cart- & gt; Empty_art ();} $ cart_item_data; }}  

No comments:

Post a Comment