I am trying to hide add to cart button. Need help

Posted In PHP
  • suthana-alley 1 year ago
    I am trying to hide add to cart button in Magento 2 as i have implemented all the steps that i have seen in the tutorial [https://magenticians.com/hide-add-to-cart-guest-users-magento-2/](https://magenticians.com/hide-add-to-cart-guest-users-magento-2/) but still the button is not hidden. Can any one guide me on this ?
    <code>
    use Magento\Framework\Event\Observer;
    use Magento\Framework\Event\ObserverInterface;
    use Magento\Customer\Model\Session as CustomerSession;
    
    class AddHandles implements ObserverInterface
    {
        protected $customerSession;
        public function __construct(CustomerSession $customerSession)
        {
            $this->customerSession
        }
    
        public function execute(\Magento\Framework\Event\Observer $observer)
        {
            $layout = $observer->getEvent()->getLayout();
    
    //To check that customer is logout
            if (!$this->customerSession->isLoggedIn())
            {
                $layout->getUpdate()->addHandle('customer_logged_out');
            }
        }
    }
    </code>

    I am trying to hide add to cart button in Magento 2 as i have implemented all the steps that i have seen in the tutorial https://magenticians.com/hide-add-to-cart-guest-users-magento-2/ but still the button is not hidden. Can any one guide me on this ? use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Customer\Model\Session as CustomerSession;

    class AddHandles implements ObserverInterface { protected $customerSession; public function __construct(CustomerSession $customerSession) { $this->customerSession }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $layout = $observer->getEvent()->getLayout();
    

    //To check that customer is logout if (!$this->customerSession->isLoggedIn()) { $layout->getUpdate()->addHandle('customer_logged_out'); } } }

  • devdojo 1 year ago
    Hi @suthana-alley
    
    I would love to try and help out, but I'm not too familiar with Magento. But I'll make sure to put it on my list of things to learn so that way I could help you out later on down the road :)

    Hi @suthana-alley

    I would love to try and help out, but I'm not too familiar with Magento. But I'll make sure to put it on my list of things to learn so that way I could help you out later on down the road :)

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
tnylea
Cheers Friend!

I'm Tony, the creator of this site. I'm trying to increase my twitter following. Want to follow me?

Follow @tnylea If not, no worries :)