I would like to check the cart for ITEM A,
if ITEM A is present add ITEM B,
if BOTH are present DO NOTHING.
I have this code below to work with. Its working but need to check if both items are in cart and not add another item. Thanks for any help.
// add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product1_id = 66;
$product2_id = 88;
$found = false;
//check if product1 is in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product1_id )
$found = true;
}
// if product1 found, add product2
if ( $found )
$woocommerce->cart->add_to_cart( $product2_id );
} else {
// check for product2 here?
}
}
}