Forum Replies Created

Viewing 1 replies (of 1 total)
  • I found this action in the (great) plugin code:
    wc_csr_before_remove_expired_item

    Based on this, if an item is expired that’s part of a bundle, it’s possible to remove the bundle is part of too. Code below also shows how this can remove composite products too.

    function remove_expired_cart_item_parent($cart_id, $cart){
    if (null === $cart) {
    // This should never happen, but better to be safe
    $cart = WC()->cart;
    }

    if (isset($cart->cart_contents[ $cart_id ][‘composite_parent’])){
    // If belongs to composite, remove
    $cart->remove_cart_item( $cart->cart_contents[ $cart_id ][‘composite_parent’] );
    WC()->session->set(‘cart’, $cart->cart_contents);
    }

    if (isset($cart->cart_contents[ $cart_id ][‘bundled_by’])){
    // If belongs to bundle, remove
    $cart->remove_cart_item( $cart->cart_contents[ $cart_id ][‘bundled_by’] );
    WC()->session->set(‘cart’, $cart->cart_contents);
    }

    return;
    }

    Could be cleaner but you get the idea.

Viewing 1 replies (of 1 total)