Last active
March 12, 2017 02:18
-
-
Save fervous/2b9035f51f1de43eb3aa353787038a0f to your computer and use it in GitHub Desktop.
only one vendor's items in the cart at once- one vendor checkout. (haven't tested yet 8/22/2016 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment