Are you looking to hide Add to cart button in Magento 2 store?
Magento 2 is a powerful ecommerce platform with plenty of valuable features. You can do many customizations within the dashboard.
For example:
- How to Create a Cart Price Rule in Magento 2?
- How to Create Coupon Codes in Magento 2?
- How to Create Admin User in Magento 2?
But for some customization, like hiding the Add to Cart button, you have to add several lines of code to the store.
In this quick tutorial, I will show you how to hide Add to Cart button in Magento 2.
Why hide Add to Cart button?
Though, showing Add to Cart button is critical and necessary for the success of the ecommerce store. In fact it is a prominent call to action button.
However, hiding Add to Cart button is helpful in many scenarios. Some reasons are:
Product Out of Stock: If the product is not in inventory, you would like to show the βnotify meβ button instead of the Add to Cart button. Notify button to provide an option to the customer to get a notification when the product arrives.
Custom Pricing: Sometimes, the product does not have any fixed cost. There are too many variables involved that you have to give custom quotations. Magento owners can show the Request Quote button in place of the Add to cart button.
Login Users: Few ecommerce niche stores have the standard practice of showing the pricing only to the login users. If the user is not registered and logged in, the Add to Cart button will stay hidden.
To execute any scenario, you will have to hire a Magento developer. These actions require coding and custom-built modules.
However, to hide Add to Cart button, you can do it yourself by following this tutorial.
How to hide Add to Cart button in Magento 2?
Step 1: Navigate to this path – Vendor\Module\etc
Step 2: Create a di.xml file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Product">
<plugin name="hidecartbutton" type="Vendor\Extension\Plugin\Hidecartbutton" sortOrder="32"/>
</type>
</config>
Step 3: Navigate to the Vendor\Module\Plugin path
Step 4: Create a HideButton.php file
<?php
namespace Vendor\Extension\Plugin;
use Magento\Catalog\Model\Product;
class Hidecartbutton
{
public function afterIsSaleable(Product $product)
{
return [];
}
}
Step 4: Finally, clean the Magento cache and clear the Redis cache.
Check the store front end to find that the Add to Cart button is not there anymore.
Wrap Up
Scarcity is a marketing tactic that uses FOMO to promote a product.
If the customer does not see an Add to Cart button, it will intrigue them to take action to know the pricing of the product.
In this quick tutorial, we learn how to hide the Add to Cart button. If you encounter any issues, please leave them in the comment section.