Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3762744
Removing products from composite once in Basket
Open

Comments

  •  2
    Josh started the conversation

    Hi there,

    Is it possible to remove individual products that have been added to the cart as a composite product?

    e.g. if we add all products https://angliancompressors.com/product/atlas-copco-g5-ff-rm-air-compressor/, we get the photo in the attachment.

    I'd like to then give the option to remove certain items if they wish.

    I'm of course happy to pay for the pro version.

    Attached files:  anglian compositre.png

  •  1,281
    Dustin replied

    Hi Josh,

    Please add the custom code below. (How to add custom code? ↗):

    add_filter( 'woocommerce_cart_item_remove_link', function ( $link, $cart_item_key ) {
    	if ( isset( WC()->cart->cart_contents[ $cart_item_key ]['wooco_parent_key'] ) ) {
    		$_product = WC()->cart->cart_contents[ $cart_item_key ]['data'];
    
    		return sprintf(
    			'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">&times;</a>',
    			esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
    			/* translators: %s is the product name */
    			esc_attr( sprintf( __( 'Remove %s from cart', 'woocommerce' ), wp_strip_all_tags( $_product->get_name() ) ) ),
    			esc_attr( $_product->get_id() ),
    			esc_attr( $_product->get_sku() )
    		);
    	}
    
    	return $link;
    }, 99, 2 );

    Then, you can remove the component product from the composite:

    6187115652.png

    Best regards,
    Dustin

  •  2
    Josh replied

    Hi Dustin,

    That's amazing, thanks so much.

  •  4
    Fernando Daniel Stal replied

    Excellent and what about change the quantity of a component?