2

Would there be any way to remove cart products from your id on page load? I'm working on it, I researched a lot too, but I found almost nothing that could help me to do a function to remove products from the cart according to its id in loading or reloading the page, since this was something specific, since only you can have a product of a category in each request and I wish I could handle that exception that exists. Thanks in advance.

  • Could you be clearer in your question please ? because psk is really blurry – PЯINCƏ Sep 11 '17 at 22:01
  • @Prince I wrote the question again, now being more clear and objective. – Matheus Portela Sep 12 '17 at 16:19
1

I don't know if this is what you want but, if i understand well you want to remove some product from cart according to the id if this product.

$productId = 10; // the product id that you want to remove it

$cart  = Mage::helper('checkout/cart');
$items = $cart->getCart()->getItems();
foreach ($items as $item) {
    if ($item->getProduct()->getId() == $productId) {
        $itemId = $item->getItemId();
        $cart->getCart()->removeItem($itemId)->save();
        break;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.