I am running an update on my customer list. In this i am retrieving the customer telephone number using

$telephone_number =  $customer->getPrimaryBillingAddress()->getTelephone();

If the customer doesn't has any address there were an error message like below

Fatal error: Call to a member function getTelephone() on a non-object in /var/www/vhosts/abc.com/public_html/custxxxxxxxx_XXX.php on line 44

I understood that this error is coming because of the customer doesn't have any address. so before using

$telephone_number =  $customer->getPrimaryBillingAddress()->getTelephone();

is there any way to check the customer has any address?


This should return all customer addresses $customer->getAddresses() so count($customer->getAddresses()) should return quantity of addresses of customer

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.