When it comes to e-commerce, the Add to Cart button is the most significant button. Ultimately, buyers cannot finish a transaction until the item is placed in the cart. Top e-commerce websites have the “add to cart” button thoughtfully positioned in many locations.
Although the arrangement may seem arbitrary to you, there is a science involved in choosing where to put them. Nonetheless, there are situations where it is preferable not to have this button displayed at all. Given that it would discourage customers from purchasing the goods, you might be questioning why this is being done.
It is obviously nonsensical because it will negatively impact both the consumer experience and the store’s profitability. Although it is true that an “add to cart” button is necessary for an e-commerce store to function, there are circumstances in which business owners may wish to conceal this crucial button. Let’s start by discussing the why of this button before going over how to hide it.
Motives for Magento 2’s Add to Cart Button to be hidden:
Store owners may want to hide or disable the add-to-cart button for the following reasons:Make them register:
Customers divulge sensitive information that they would not otherwise be able to obtain when they register for an e-commerce store. Preventing people from seeing the prices and the “add to cart” button without being inquisitive about them and being forced to enroll. You can target them with tailored marketing techniques based on the data they provide throughout the sign-up process.Future Products:
There are two advantages to showcasing products that you have not yet launched. In the first place, it generates buzz in the industry; secondly, their keywords may appear in search results before the official release of the product. Typically, the debut date is indicated so that buyers will know to buy it as soon as it becomes available. Since some products are obviously not yet available for purchase, it will be appropriate to hide the “add to cart” button for them.Products Out of Stock:
Products may run out of stock, so it makes no sense to let shoppers add them to their carts. Alternatively, you could let them sign up for these things so they may be notified when they restock. They will be informed via the Out of Stock Notification that the products are now available, and since they are already interested, they may decide to purchase them.Particular Items:
Store owners might not want to offer some things at this time because they believe they need more features or aren’t finished. Then, there can be sample items that aren’t available for purchase. It seems reasonable to restrict buyers' ability to purchase these things, and the solution is to conceal the add-to-cart button. Additionally, store owners may wish to hide prices and allow customers from particular customer groups and countries to add items to their carts without logging in.Methods to Hide Add to Cart Button in Magento 2:
The add-to-cart button can be hidden using one of two techniques. The best approach for you will simply depend on your priorities. Both work effectively.Method 1: Manually Hide Add to Cart Button with Code
The following method will hide the add-to-cart button in Magento 2 from the product page as well as the category page.- Create a di.xml file in Vendor\Module\etc and copy the below code
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Product"> <plugin name="hidebutton" type="Vendor\Module\Plugin\HideButton" sortOrder="10" disabled="false" /> </type> </config>
- Create a HideButton.php file in Vendor\Module\Plugin and copy the code below.
<?php namespace Vendor\Module\Plugin; use Magento\Catalog\Model\Product; class HideButton { public function aroundIsSalable(Product $product, \Closure $result) { return 0; } }Run php bin/magento setup:upgrade and refresh the page