General

How To Hide Add To Cart Button in Magento 2

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?

Click to rate this post!
[Total: 3 Average: 3.7]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

14 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

2 days ago

Magento 2 Extensions Digest October 2024 (New Release & Updates)

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

2 days ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

2 weeks ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago