WordPress.org

Forums

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

  1. Paulo Iankoski
    Member
    Posted 1 year 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 1 year 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;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic