Menu Close
    Hire us Request quote Reading list Switch to dark mode

    Restrict Add To Cart According To Condition In Magento 2

    Here we learn how to restrict ‘Add To Cart’ according to condition in Magento 2

    For this i’ll use controller_action_predispatch_checkout_cart_add observer

    1=> We create events.xml file in app/code/NameSpace/ModuleName/etc/frontend location and add following code


    2=> Now we create your class where we check condition and restrict Add To Cart

    Create RestrictAddToCart.php file at NameSpace\ModuleName\Observer\ location


    now flush your magento2 cache and it will working on your magento2 website.
    after click add to cart button 1st it check condition and proceed according to condition
    Thanks 🙂

    . . .

    Comment (1)

    Add Your Comment

  • Jancy
    Hi,
    I am using magento 2.1.8.
    I have checked the controller_action_predispatch_checkout_cart_add event.
    But in my case,this is not fire 🙁
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close