Last active
August 17, 2016 02:49
-
-
Save jamsea/45d8d4b7b5b0ad074f32d72e0199e578 to your computer and use it in GitHub Desktop.
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
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; | |
var_dump($values); | |
} | |
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 ); | |
// Debug check if numbers are actually appearing | |
echo "product_in_cart_vendor_id" . $product_in_cart_vendor_id; | |
echo "product_added_vendor_id" . $product_added_vendor_id; | |
if($product_in_cart_vendor_id === $product_added_vendor_id) { | |
return $cart_item_data; | |
} else { | |
wc_add_notice( 'Whoa hold up. You could only add items from one vendor at a time in your cart', 'error' ); | |
$woocommerce->cart->empty_cart(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment