How to check a customer has a billing or shipping address using customer id?
-
29-09-2020 - |
Question
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?
Solution
This should return all customer addresses $customer->getAddresses()
so count($customer->getAddresses())
should return quantity of addresses of customer
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange