Question:I tried various snippets to achieve what I need but I’m failing miserably.
I need products contained within categories B, C & D removed from the cart if a product in category A is present/added. At this point, I would be happy with just removing products in categories B, C & D if a specific product ID is present/added.
I think the code from Remove other products if certain product category is present on WooCommerce checkout answer code is close, but I just can’t seem to adapt it for my needs.
Answer:You need to loop first to detect any “Category A” product in the cart. If there is one, then loop again to find any product from other target categories to remove.
This edit should do it.
If you have better answer, please add a comment about this, thank you!