Howdy Magento Folks?,
What’s going on? I hope all are reading up with good health. Let’s start with today’s topic How To Hide Add To Cart Button in Magento 2. Don’t miss our previously published article How to Enable Persistent Shopping Cart in Magento 2. Let’s Dive In?
Introduction:
Mainly, the Magento 2 store owners always allow their users to add products at the cart for the checkout process. Many times the store owners have their individual rules of adding products for checkout. For example, there are products that are upcoming in the store then obviously there is a requirement to hide the add to cart or Request for Quote button in Magento 2. Sometimes the store owner wishes to hide the price and add a cart button then Solve this problem by integrating MageComp’s Magento 2 Hide Product Price extension. Let’s hide the add to cart button in Magento 2 also for restricting the users not to display until and unless they are not Logged In. Let’s start.
Steps to Hide Add To Cart Button in Magento 2:
Step 1: Firstly Create a di.xml file at the given below path.
Vendor\Module\etc
<?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 2: Now, Create HideButton.php file at the given below path
Vendor\Module\Plugin
<?php namespace Vendor\Extension\Plugin; use Magento\Catalog\Model\Product; class Hidecartbutton { public function afterIsSaleable(Product $product) { return []; } }
Step 3: Now, just run php bin\magento cache:clean and refresh the page and you will realize the add to cart button will be hidden from your store pages.
Final Words:
Hopefully, all are able to hide the add to cart button from your Magento 2 Store but incase any difficulties then do contact MageComp Support. Also, share with your developer friends for helping them in solving the hide add to cart button in Magento 2. Do share your reviews with us in the comment section below.
Happy Coding?