How To get Current Magento 2 Customer ID

How to get current Magento 2 customer id programmatically after logged in.

You can use “\Magento\Customer\Model\Session ” to retrieve the current customer session and use it to get customer id.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get(‘\Magento\Customer\Model\Session’);
$custom_id =  $customerSession->getCustomer()->getId();

Leave a Reply

avatar
  Subscribe  
Notify of