First You need to create a object instance:
$om = \Magento\Framework\App\ObjectManager::getInstance();
After That:
<?php $customerSession = $om->get('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) { echo $customerSession->getCustomer()->getId()."<br/>"; // get Customer Id echo $customerSession->getCustomer()->getName()."<br/>"; // get Full Name echo $customerSession->getCustomer()->getEmail()."<br/>"; // get Email Name echo $customerSession->getCustomer()->getGroupId()."<br/>"; // get Customer Group Id } ?>
9 Comments
Jonas · June 1, 2016 at 11:33 pm
Hi
Can you explain how can I get the group name form the group id?
Thanks
Jonas
jon · November 18, 2016 at 3:25 pm
check this http://www.onlinecode.org/blog/2016/11/18/magento-get-customer-group-id-group-name/
Sergey · December 3, 2016 at 6:58 pm
Hi, Jonas! Here you can find, how to get the group name by group id: http://blog.sergey-lysenko.ru/2016/12/get-customer-group-name-from-customer-group-id.html
Ratnesh · July 2, 2016 at 2:57 pm
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create(‘Magento\Customer\Model\Session’);
if ($customerSession->isLoggedIn()) {
}
Ratnesh · July 2, 2016 at 2:58 pm
Please replace get to create
PRAKASH · September 1, 2016 at 5:51 pm
This not working in home page.
Santosh Sharma · December 7, 2016 at 2:35 pm
$om = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $om->create(‘Magento\Customer\Model\Session’);
if ($customerSession->isLoggedIn()) {
echo $customid = $customerSession->getCustomer()->getId();
echo $customgp = $customerSession->getCustomer()->getGroupId();
}
its will show on all pages
Arles · January 11, 2017 at 9:05 pm
Thanks for the info!
Jeff Monschke · February 3, 2017 at 2:38 am
Using the object manager directly is not the recommended way to create objects in Magento 2, as you should be utilizing the dependency injection capabilities that are baked in.