I observe the event sales_order_place_after If I buy like guest or new user custumer name, lastname is NULL if I buy logged name, lastname is normal


I use Magento 2.1.11

How fix it ?


Use this solution

$Order =$observer->getOrder();

    { // if  customer is guest
    $firstname = $Order->getBillingAddress()->getFirstname();
    $lastname = $Order->getBillingAddress()->getLastname()
       $firstname = $Order->getCustomerFirstname();
    $lastname = $Order->getCustomerLastname()
  • @Andszej, please accept the answer. So it will help to others. – kunj Jun 14 '18 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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