0

How to add customer group name in email template magento2

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

2 Answers 2

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

6
  • How can it use in email? @sumit Aug 25, 2019 at 11:04
  • Pass customer group as variable in email function and use it in your email template.
    – Sumit
    Aug 25, 2019 at 11:23
  • Thank you it is working @Sumit Aug 27, 2019 at 10:54
  • You're welcome :)
    – Sumit
    Aug 27, 2019 at 10:55
  • Where should I put this code?
    – Max Leps
    Mar 30, 2022 at 20:01
0

After used that code how can I use Customer Group Name as variabile in email templates? Could You explain this step? Thanks @Sumit

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.