How To Remove Block Depending on Config Setting in Magento 2

How To Remove Block Depending on Config Setting in Magento 2

I’ve earlier posted a solution to remove a block from the layout in Magento 2

But what if you want to remove block depending on config setting in Magento 2 store?

It may happen that based on certain conditions, you want to display a block or eliminate it.

For example, you want to disable the account registration based on a specific condition and hence remove the login block.

Implement the below method for similar scenarios and handle conditional behaviors like a pro! 😎

Method to Remove Block Depending on Config Setting in Magento 2:

  1. Create events.xml file in app\code\[Vendor]\[Module]\etc
  2. Create RemoveBlock.php file in app\code\[Vendor]\[Module]\Model\Observer

That’s it.

It was never this easy to eliminate block depending on config setting in Magento 2!

However, if you still have doubts about the implementation, please mention them in the Comments section below and I’d be happy to help.

Feel free to share the solution via social media with the fellow developers 🙂

Thanks.

Get E-commers Updates in Your Inbox

Thank you for subscribing.

Something went wrong.

5
(based on 7 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.