0

How to add customer group name in email template magento2

1
  • on which email template/ new order, customer creation? – Amit Bera Aug 25 '19 at 13:33
2

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!!!

4
  • How can it use in email? @sumit – Magento Aug 25 '19 at 11:04
  • Pass customer group as variable in email function and use it in your email template. – Sumit Aug 25 '19 at 11:23
  • Thank you it is working @Sumit – Magento Aug 27 '19 at 10:54
  • You're welcome :) – Sumit Aug 27 '19 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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