0

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

1
  • Can you please provide some more information in detail where exactly you need customer id? While placing order on checkout or after placing the order on success page? Yes, you can get it but the ways are different depending upon the case where you need it exactly. Commented May 29, 2020 at 10:06

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

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