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();

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *