How To Remove Item From Cart By Magento Product Id Programmatically

How can I remove a item from Magento cart by product Id programmatically

Here is a example

$pid = 1;

$cart = Mage::getModel('checkout/cart')->getQuote();
$items = $cart->getAllItems();
foreach($items as $item){
    if($item->getProduct()->getId() == $pid){
        $itemId = $item->getItemId();
        Mage::getModel('checkout/cart')->removeItem($itemId)->save();
        break;
    }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments