I would like to hide link in user account customer_account.xml based on role they are in. Let say we have group B2B and i want to hide block customer-account-navigation-product-reviews-link.

To remove this block I need flowing code: <referenceBlock name="customer-account-navigation-product-reviews-link" remove="true"/>

To remove it in condition i know that I will require ifconfig <referenceBlock name="customer-account-navigation-product-reviews-link" ifconfig="??" remove="true"/>

However i have no idea how to get that true/false condition here. Is this require special class if so were to put it and how it might look ?

  • Is any solution worked for you? Commented May 28, 2021 at 4:31

2 Answers 2


In order to conditionally remove block from layout use Magento 2 event layout_generate_blocks_after as below.

Define the event in events.xml file.

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_generate_blocks_after">
        <observer instance="Vendor\YourModule\Observer\Frontend\Removeblocks" name="layout_generate_blocks_after"/>

Define Observer file Removeblocks.php and add below code in file.


namespace Vendor\YourModule\Observer\Frontend;
use Magento\Framework\Event\ObserverInterface;
class Removeblocks implements ObserverInterface
    public function execute(\Magento\Framework\Event\Observer $observer)
       //your condition here
       $layout = $observer->getLayout();

I hope it helps you. Thanks!

  • execute should be (\Magento\Framework\Event\Observer $observer) Commented May 31, 2021 at 9:03

I don't think you'll be able to pull in values like that within the XML as it will be on a per-customer basis and the ifconfig values are static.

Your best bet will probably be to write a plugin for the _toHtml() function in


where the individual links are rendered.

You could then use the Magento\Customer\Model\Session class to get the customer group ID ($customerSession->getCustomer()->getGroupId();) which you can check before rendering the unwanted item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.