Magento – Magento2: How to get guest email address in checkout

checkoutcustomeremailloggingmagento2

Please, how to get guest email address in checkout?

Best Answer

In your custom-method.js file

define(
[
    'jquery',
    'Magento_Checkout/js/model/quote'
],
function ($,quote,Component,) {
    'use strict';

    return Component.extend({

        defaults: {
            template: 'Namespace_ModuleName/custompayment/form_template'
        },

        getGuestEmail: function () {
            return quote.guestEmail;
        }

    });
}
);

After that just call that function you will get guest email address If you want register customer email address then use following:

        getEmail: function () {
            return window.checkoutConfig.customerData.email;
        }