If we ever need to clear Magento’s shopping cart, use the snippet of code below. If we need to clear the user’s entire session, including the shopping cart, shipping information, billing information and chosen payment methods, please refer to the snippet further below.
Clear shopping cart:
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){ Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save(); }
Clear entire session:
Mage::getSingleton(‘checkout/session’)->clear();
0 Comments