How to Remove Block From Layout in Magento 2
Magento 2 store designs must constantly be updated based on the business requirements, latest trends, and for the improvement of customer experience.
As a part of this process, you may require to add or remove a block from the layout in Magento 2. Here, I’ve shown how to remove block from layout in Magento 2 with a programmatic solution.
One can use this method in various ways. For example, the store is running a Christmas offer and had added a promotional offer block on the home page which needs to be removed post offer. Also, you may want to remove any default blocks for which the method is useful.
I’ve taken an example of removing the coupon code application block on the checkout page. If you want to remove a promo code that you are currently offering, you can do so by removing that block from the checkout.
Steps to Remove Block From Layout in Magento 2:
All you have to do is:
<referenceBlock name="block_name" remove="true"/>
For example, remove the coupon code block from the checkout cart page:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="checkout.cart.coupon" remove="true"/>
Any doubts in the implementation? Mention them in the Comments section below and I’d be glad to help 😊
I’d be very grateful if you share this helpful post on social media to fellow developers!