0

I'm altering "review" form in checkout process and adding custom submit handler. From that handler, if user is registered I can get it's email address as:

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$email = $user->getEmail();

But if I go to checkout as a guess user I can not get email of anonymous user that way - returns null.

How can I get guest user email address? I need a way to get email provided on previous checkout page, no matter if user is registered or not.

1 Answer 1

0

Found the way over the cart:

$store = \Drupal::service('commerce_store.current_store')->getStore();
$cart = \Drupal::service('commerce_cart.cart_provider')->getCart('default', $store);
$email = $cart->getEmail();

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.