How remove link from customer menu when customer in general group?

How remove link from customer menu when customer in general group?

September 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How remove link from customer menu when customer in general group?

Removing Menu Links for General Customer Group in Magento 2

As a seasoned developer at Laravel Company, I often encounter clients struggling to manage their menu visibility based on customer groups. In your case, you want to hide specific links from the menu when the customer is part of the ‘General’ group in Magento 2. Let’s dive into how we can achieve this.

Understanding Customer Menu Structure

In Magento 2, the top menu structure is managed through XML configuration files located under app/design/frontend/{package}/{theme}/Magento_Theme/layout. These files define the layout of your storefront and include blocks like <block type="Magento\Cms\Block\Block" template="cms/block.phtml">.

The ifconfig condition allows you to apply conditions based on system configuration or other variables. However, this won’t help us hide links based on customer groups directly.

Hiding Menu Links Based on Customer Group

To achieve this, we need to create a custom module that overrides the menu rendering process specifically for customers in the ‘General’ group. Here’s a step-by-step guide:

  1. Create a Custom Module

    • Navigate to app/code and create a new folder called LaravelCompany_CustomMenu.
    • Inside this folder, create another folder named etc and within it, make a file called di.xml.
  2. Overriding the Menu Renderer

In the di.xml file, we’ll override the Magento\Cms\Controller\Block to include our custom logic for hiding menu items.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Cms\Controller\Block">
        <arguments>
            <argument name="requestData" xsi:type="array">
                <item name="general" xsi:type="string">general_group</item> <!-- Set this to the ID of your 'General' customer group -->
            </argument>
        </arguments>
    </type>
</config>

Replace general_group with the actual ID of your ‘General’ customer group.

  1. Creating the Custom Renderer
  • Create a new file called Block.php inside app/code/LaravelCompany/CustomMenu/Controller.
  • Implement the logic to hide menu items based on the customer group:
namespace LaravelCompany\CustomMenu\Controller;

use Magento\Customer\Model\Session;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;

class Block extends \Magento\Cms\Controller\Block
{
    protected $customerSession;

    public function __construct(
        RequestInterface $request,
        Session $customerSession
    ) {
        $this->customerSession = $customerSession;
        parent::__construct($request);
    }

    public function execute()
    {
        if ($this->customerSession->isLoggedIn() && $this->customerSession->getCustomer()->getGroupId() == 1) { // Assuming 'General' group ID is 1
            return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
        }

        return parent::execute();
    }
}
  1. Clearing the Cache

After making these changes, clear your Magento cache by running bin/magento cache:clean in your terminal.

Conclusion

By following these steps, we successfully created a custom module that overrides the menu rendering process to hide specific links for customers in the ‘General’ group. This approach ensures clean and maintainable code while providing the desired functionality.

Remember, at Laravel Company, we always strive to provide solutions that are not only effective but also efficient and easy to manage. If you have any further questions or need assistance with Magento development, feel free to contact us.

Happy coding!

Magento 2 Extensions Themes Configuration

Our network