0

I want to remove customer_account_navigation-reports block from customer account on the frontend for specific customer group i.e. Distributor

How can I do this?

2

1 Answer 1

1

I have found the soution.

  1. Create a custom module Abweb_Customer.

  2. Create registration.php in Abweb/Customer and module.xml in Abweb/Customer/etc folder.

  3. Create di.xml in Abweb/Customer/etc folder with following code.

    <?xml version="1.0" ?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Controller\Account\Index" type="Abweb\Customer\Controller\Account\Index" />
    </config>
    
  4. Create Index.phpin Abweb\Customer\Controller\Account folder with following code.

    <?php
    namespace Abweb\Customer\Controller\Account;
    use Magento\Framework\App\Action\Context;
    use Magento\Framework\View\Result\PageFactory;
    
    class Index extends \Magento\Customer\Controller\Account\Index
    {
    /**
    * @var PageFactory
    */
    protected $resultPageFactory;
    protected $customersession;
    
    public function __construct(
    Context $context,
    \Magento\Customer\Model\Session $customersession,       
    PageFactory $resultPageFactory
    ) {
    parent::__construct($context,$resultPageFactory);
    $this->customersession=$customersession;
    $this->resultPageFactory = $resultPageFactory;
    }
    public function execute()
    {
    if($this->customersession->isLoggedIn())
    {
        $cgid = $this->customersession->getCustomer()->getGroupId();  // get Customer Group Id
        $resultPage = $this->resultPageFactory->create();
        $layout = $resultPage->getLayout();
    
        if($cgid!="10") // Distributor Customer Group
        {
            $block = $layout->getBlock('customer_account_navigation-reports'); // block name
            $layout->unsetElement('customer_account_navigation-reports'); //remove block
            return $resultPage;
        } else {
            return $resultPage;
        }
    
    }
    }
    }
    
  5. Done. Now all you have to do is change the customer-group code and block name that you want to remove.

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.