My code is
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace My\Module\Block; use Magento\Framework\View\Element\Template; class Abc extends Template { protected $ _customerSession; /** * @param Template\Context $ context */ public function __construct( Template\Context $ context, \Magento\Customer\Model\Session $ customerSession ) { parent::__construct($ context); $ this->_customerSession = $ customerSession; } public function getCustomerDetail(){ if($ this->_customerSession->isLoggedIn()) { echo $ this->_customerSession->getCustomer()->getId(); echo $ this->_customerSession->getCustomer()->getName(); echo $ this->_customerSession->getCustomer()->getEmail(); echo $ this->_customerSession->getCustomer()->getGroupId(); } } }