How to add customer group name in email template magento2
2 Answers
You can use below code to get customer group details from customer id.
protected $_customerSession;
protected $_customerGroupCollection;
public function __construct(
\Magento\Customer\Model\Session $customerSession,
\Magento\Customer\Model\Group $customerGroupCollection
) {
$this->_customerSession = $customerSession;
$this->_customerGroupCollection = $customerGroupCollection;
}
public function getCustomerGroup()
{
echo $currentGroupId = $this->_customerSession->getCustomer()->getGroupId(); //Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection->load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
}
Hope it helps!!!
-
-
Pass customer group as variable in email function and use it in your email template.– SumitAug 25, 2019 at 11:23
-
-
-
After used that code how can I use Customer Group Name as variabile in email templates? Could You explain this step? Thanks @Sumit