2

I am using below code to get customer firstname and lastname from billing address but it is not returning any value. Can someone please help how we can get those information from billing address. Any help will be great.

$order = Mage::getModel('sales/order')->loadByIncrementId('700590221');
$billingAddress     = $order->getBillingAddress();
echo 'FirstName: ' . $billingAddress->getFirstName() . PHP_EOL;
echo 'LastName: ' . $billingAddress->getLastName();

2 Answers 2

2

There are few issue may be in your code,

getFirstName() should be getFirstname() as at db table field name is firstname.getFirstName indicated at the filed name is first_name and that is wrong

and getLastName() should be getLastname() as at db table field name is lastname().getLastName indicated at the filed name is last_name and that is wrong

Also you check the order 700590221 exists at system*.

For first case, you can check availability by $order->getId() give numeric value if order exits at system else give value false

Code

<?php
  $order = Mage::getModel('sales/order')->loadByIncrementId('700590221');
  if($order && $order->getId()) {
      $billingAddress     = $order->getBillingAddress();
      echo 'First Name: ' . $billingAddress->getFirstname().PHP_EOL;
     echo 'Last Name: ' . $billingAddress->getLastname();
  }
?>
0
2

Replace your code with this :

$order = Mage::getModel('sales/order')->loadByIncrementId('700590221');
    $billingAddress     = $order->getBillingAddress();
    echo 'FirstName: ' . $billingAddress->getFirstname() . PHP_EOL;
    echo 'LastName: ' . $billingAddress->getLastname();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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