is there any way to get customer id from guest checkout?


Use below code to get guest email using email you can identify customer id

private $session;
protected $_customer;
protected $_storemanager;

public function __construct(
    \Magento\Customer\Model\CustomerFactory $customer,
    \Magento\Store\Model\StoreManagerInterface $storemanager,
    \Magento\Checkout\Model\Session $session,
) {
    $this->session = $session;
    $this->_customer = $customer;
    $this->_storemanager = $storemanager;

public function getCustomerIdFromQuote() {
     $guestEmail = $this->session->getQuote()->getCustomerEmail();
     $websiteID = $this->_storemanager->getStore()->getWebsiteId();
     $customer = $this->_customer->create()->setWebsiteId($websiteID)->loadByEmail($guestEmail );
     $customerId = $customer->getId();


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.