i in condition add product product cart. whenever purchasing product complementary product should added cart automatically. here have been trying :
function save_gift_wrap_fee( $cart_item_key ) { if( $_post['offered-product-id'] ) { global $woocommerce; if($_post['offered-product-variation-id']){ $woocommerce->cart->add_to_cart($_post['offered-product-id'],'1',$_post['offered-product-variation-id'],array('flavour'=>$_post['offered-product-variation-name']),null); } else{ $woocommerce->cart->add_to_cart($_post['offered-product-id'],'1'); } wc()->session->set( $cart_item_key.'_offered_product_id', $_post['offered-product-id'] ); wc()->session->set( $cart_item_key.'_offered_product_price', $_post['offered-product-price'] ); wc()->session->set( $cart_item_key.'_offered_variation_id', $_post['offered-product-variation-id'] ); } else { wc()->session->__unset( $cart_item_key.'_offered_product_id' ); } } add_action( 'woocommerce_add_to_cart', 'save_gift_wrap_fee', 1, 5 ); i adding product session can reset price discounted price. problem whenever try add product, main product got added cart complementary 1 adding available stock cart , showing message "you cannot add amount cart — have 3 in stock , have 3 in cart.".
i guessing problem add_to_cart() parameters, have tried followings :
$woocommerce->cart->add_to_cart($_post['offered-product-id'],'1',$_post['offered-product-variation-id'],array('flavour'=>$_post['offered-product-variation-name']),null); and
$woocommerce->cart->add_to_cart($_post['offered-product-id'],1,$_post['offered-product-variation-id'],array('flavour'=>$_post['offered-product-variation-name']),null); getting same message both lines.
any suggestions ?
im not sure solve problem in code, plugin trying http://woogang.com/product/woocommerce-chained-products-extension/
Comments
Post a Comment