If you want to tailor your customer's experience to their needs you have to gather as much information about them as possible. Displaying unique pricing details or offering different shipping services based on customer groups required you to get current customer data in Magento.
Besides, customer age, gender and location are valuable marketing insights you can use to tweak your strategy.
Post Contents [hide]
Get Current Customer in Magento 2
You can get current customer in Magento via \Magento\Customer\Model\Session model using two methods.
public function __construct(
$this->customerSession = $customerSession;
public function getCurrentCustomer()
Using Object Manager
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
$customer = $customerSession->getCustomer();
Get Current Customer ID in Magento
$customerId = $this->customerSession->getCustomerId();
Get Current Customer Group ID in Magento 2
$customerGroupId = $this->customerSession->getCustomerGroupId();