How to get current customer data in Magento 2
Collecting the data of current customers provides you the important details to know who your customers are, what they want, and how to serve them better. Magento 2 store admin may want to implement certain features based on customer attributes of current users. For example, only current customers are allowed to view the price details. Admin may want to give shipping services to particular customer groups only.
Admin needs to store customer attributes value for such features. To get current customer data in Magento 2, one needs to follow one of the below methods.
$om = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $om->get('Magento\Customer\Model\Session'); $customerData = $customerSession->getCustomer()->getData(); $customerId = $customerSession->getCustomer()->getId();