I have two product types, one of them simple product $cart_item['default-engraving']
and the other one credit product $cart_item['default-engraving'] && $cart_item['iconic-engraving']
. I’m trying to find a solution how to make that if I add simple product to a cart, credit product shouldn’t be added. Or if I add credit product to a cart, simple product should’t be added. But if I want I could add same type for example simple product type as many as I want.
Question posted in Woocommerce
The official Woocommerce documentation can be found here.
The official Woocommerce documentation can be found here.
3
Answers
You may try this
Update: Is not possible to detect custom cart item data on add to cart event.
Checking cart items will allow you to prevent having cart items that have
$cart_item['default-engraving']
and$cart_item['iconic-engraving']
at the same time:Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Original answer: (it can’t work for your case as it’s not possible to detect that on add to cart event)
Here is the way targeting the product type to allow only one in cart:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related: Allow only one product category in cart at once in Woocommerce
please check below code.