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?
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?
I have found the soution.
Create a custom module Abweb_Customer.
Create registration.php
in Abweb/Customer and module.xml
in Abweb/Customer/etc folder.
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>
Create Index.php
in 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;
}
}
}
}
Done. Now all you have to do is change the customer-group code and block name that you want to remove.