How to get Customer in product view in Magento 2
You can get customer_id, getName(), and getEmail() in the product view in Magento 2 directly from customer session. Utilize the following code:
1 2 3 4 5 6 7 8 9 10 |
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if ($customerSession->isLoggedIn()) { $customerSession->getCustomerId(); $customerSession->getCustomerGroupId(); $customerSession->getCustomer(); $customerSession->getCustomerData(); $customerSessionget->getCustomer()->getEmail(); } |
Source (