TransWikia.com

magento 2.3 call customer group Name

Magento Asked by niceonelee on November 19, 2021

i am using magnto 2.3.x,

how can i call the customer group Name in phtml

not a customer group ID.

Thanks for help

One Answer

Try this code

 protected $_session;
 protected $_customerGroupCollection;

 public function __construct(
        ................................................
        MagentoCustomerModelSession $session,
        MagentoCustomerModelGroup $customerGroupCollection,
        ................................................
    ) {
        ................................................
        $this->_session = $session;
        $this->_customerGroupCollection = $customerGroupCollection;
        ................................................
    }
    public function getGroup()
    {
        $currentGroupId = $this->_session->getCustomer()->getGroupId(); //Get customer group Id 
        $collection = $this->_customerGroupCollection->load($currentGroupId); 
        echo $collection->getCustomerGroupCode();//Get group name
    }

Call this method in phtml

$block->getGroup();

I Hope This Helps You.

Answered by Msquare on November 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP