Commerce – empty cart of EXISTING items when adding new item of specific order item type
When an item of a specific order item type is added to the cart, I want to remove any existing items from the cart, but keep the item that has just been added.
I presume CartEvents::CART_ENTITY_ADD is the only event I can do this in, but anything i try with ->emptyCart or ->removeItem removes both the existing items AND the item that has just been added, leaving the cart empty after adding the new item.
What is the correct way to do this?
This article was republished from its original source.
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.