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

    Remove Block From Layout on Specific Condition in magento2

    If you are working in magento2, and want to remove block from layout without any condition, then you can read blog:

    Remove block from layout

    Now, if you have a specific condition to display the block or not, then this can be achieve by observer.

    Firstly you need to create an events.xml file in your module,
    app/code/Webkul/Test/etc/frontend/events.xml


    Here, layout_generate_blocks_after observer is called after a block is rendered on the page.
    And define the file to execute on observer.

    Now, create observer file:

    app/code/Webkul/Test/Observer/RemoveBlockForDiscount.php


    Here, i am removing discount coupon block from the page.

    After adding code in your module, discount coupon block will get removed from pages, as from checkout/cart page.

    Hope this blog will help you in implementation of functionality.

    Thank you.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    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