Glad to see you again in Magento blog! Lately I have got a few messages asking me about how to hide or remove Add to Cart button from product page based on some conditions of product. I think there have been many other people having the same question and interested in the best solution for this issue. Thus I decide to write this short Magento tutorial. Although Magento does not support this feature, you can still implement it without modifying Magento core by taking some following steps:

  • Create a new module by using Module Creator
  • Insert a new event observer into config file of that module (app/code/local/Namespace/Modulename/etc/config.xml). Paste this code below into <frontend> tab.
<events>
<catalog_product_is_salable_after>
<observers>
<modulename>
<type>singleton</type>
<class>modulename/observer</class>
<method>catalog_product_is_salable_after</method>
</modulename>
</observers>
</catalog_product_is_salable_after>
</events>
  • Create model Observer in your module

(app/code/local/Namespace/Modulename/Model/Observer.php)

class Namespace_Modulename_Model_Observer
{
public function catalog_product_is_salable_after($observer)
{
$product = $observer->getProduct();
$salable = $observer->getSalable();

if($product->getSku() == 'abcxyz'){ /* product condition */
$salable->setIsSalable(false);
}
return $this;
}
}

After installing this module on your store, the Add to Cart button will be removed. It’ll look like the picture below:

Finally, please note that you need to replace Namespace and Modulename in the example above with the specific values.

Hope my post will be helpful for you. Don’t hesitate to leave comments if you have any other ideas or solutions for this issue. Nice code!

Related: 

 

Author

Alex is the CTO & Co-founder of Magestore which has been providing retail solutions for Magento merchants since 2009. He started as a Magento developer just one year after the release of the first version of Magento. With over 10 years experience of working with Magento and clients all over the world, he gained great knowledge on e-commerce development, order management systems, inventory control & retail POS.

1 Comment

Write A Comment