- How to know the Checkout Method Status of the user is Guest or Registered Magento 2?
While working on the checkout page, You can know the current customer is a Guest or registered customer using checking the customer login status.
When you need to know the status of the customer is logged in or not using javascript you need to inject JS object using the ‘Magento_Customer/js/model/customer’ file.
Create a customer object and it contains many functions to customer-related functionality.
Create a JS file in your module or theme level,
define([ 'Magento_Customer/js/model/customer', ], function (customer) { 'use strict'; return { /** * @return {String} */ getCheckoutMethod: function () { return customer.isLoggedIn() ? 'customer' : 'guest'; } }; } );
Now you need to call this.getCheckoutMethod() method to know the status of the customer.
This is useful in many scenarios when you are working with checkout customization functionality.