Support » Plugin: WooCommerce » Variable Product

  • Resolved Paulo Iankoski

    (@pauloiankoski)


    Hi guys,

    I need to avoid a product to be added in cart twice.

    Eg. I choose variation A and add to cart. Then, I choose variation B and add to cart. At this point, I need to remove variation A and put variation B single.

    How we can do this?

    Tks!

    http://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Paulo Iankoski

    (@pauloiankoski)

    I solved this way:

    add_action( 'woocommerce_add_cart_item', 'remove_duplicated_item' );
    function remove_duplicated_item($var) {
    	global $woocommerce;
    
    	foreach( $woocommerce->cart->cart_contents as $key => $value ) {
    		if( $value['product_id'] == $var['product_id'] ) {
    			unset($woocommerce->cart->cart_contents[$key]);
    			return $var;
    			break;
    		}
    	}
    	return $var;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Variable Product’ is closed to new replies.