1

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

$observer->getOrder()->getCustomerFirstname();

I use Magento 2.1.11

How fix it ?

1

Use this solution

$Order =$observer->getOrder();

    if($Order->getCustomerIsGuest())
    { // if  customer is guest
    $firstname = $Order->getBillingAddress()->getFirstname();
    $lastname = $Order->getBillingAddress()->getLastname()
    }else{
       $firstname = $Order->getCustomerFirstname();
    $lastname = $Order->getCustomerLastname()
    }
| improve this answer | |
  • @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.