0

We are Providing an option for "Add to cart" & "Delete" for each product in My account section.

what we need is if that product is added to cart, than we want to hide the "Delete" button. enter image description here

<?php
$productId = $_product = Mage::getModel('catalog/product')->load($product->getId());
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (! $quote->hasProductId($productId)) 
{
?>

<a><span>Delete</span></a>

<?php   
}
?>

I tried above code, but still "Delete" button visible after click on "Add to cart"

7
  • You can do it in 2 diff ways. 1) If your page is getting reloaded after hitting the add to cart button then you can easily check if product id exists in quote and remove the button by adding display:none to your css. 2) If its using ajax add to cart then do it from jQuery. Both are easy. Commented Jun 6, 2017 at 11:00
  • @KingshukDeb page is reloading, i am trying the code in question, but it didt worked for me, can you please check and tell what wrong i did ? or what css code will make it work......
    – user52996
    Commented Jun 6, 2017 at 11:02
  • Try to var dump $quote->hasProductId($productId); line Commented Jun 6, 2017 at 11:53
  • @simplysaif i got result : bool(false) after i used var_dump($quote->hasProductId($productId));
    – user52996
    Commented Jun 6, 2017 at 12:04
  • Mage::getSingleton('checkout/session')->getQuote()->getItemByProduct($productId)) try this code to check if item is in the cart already.. var dump it Commented Jun 6, 2017 at 12:06

1 Answer 1

0
<?php
$_product = Mage::getModel('catalog/product')->load($product->getId());
 $quote = Mage::getSingleton('checkout/session')->getQuote(); 
if (! $quote->getItemByProduct($productId))
 { 
?>
 <a><span>Delete < /span> < /a> 
<?php 
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.