Magento – Magento 2 get customer email in guest checkout

guest-checkoutmagento2

I've tried all posts on this subject but couldn't make it work.

I need to retrieve customer email during checkout, just after he fills the address form, on the select payment method page.

This info is not stored in the session (it is only if the customer is logged in).

I've checked the table "quote_address" in the database as well. The column "email" is empty while "firstname", "lastname", "street" have data.

I've tried javascript with no success either.

Where is that email stored?

Can someone help me with this? If so, please provide a detailed answer.

Thanks in advance.

Best Answer

I would use the model \Magento\Checkout\Model\Session

and then from this model, I would load the quote ($this->_checkoutSession->getQuote())

and then you can read the customer email that is in your delivery address using $quote->getCustomerEmail().

The link https://community.magento.com/t5/Magento-2-x-Programming/Uncaught-Error-Call-to-a-member-function-getQuote-on-null/td-p/92665 will show you how to get checkoutSession in your code

Related Topic