WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Variable Product (2 posts)

  1. Paulo Iankoski
    Member
    Posted 5 months ago #

    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/

  2. Paulo Iankoski
    Member
    Posted 5 months ago #

    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;
    }

Reply

You must log in to post.

About this Plugin

About this Topic