Home    Articles

 

How to get customer address in magento by cutomer id

 

Assuming that you managet to get the customer id, this is how you can get the customer address in magento, anywhere.

This code will get the customer object and it will use a loop to get all addresses that might occur in user’s settings.

#customer id here
$customerId = 1;
#load customer object
$customer = Mage::getModel('customer/customer')->load($customerId); //insert cust ID
#create customer address array
$customerAddress = array();
#loop to create the array
foreach ($customer->getAddresses() as $address)
{
   $customerAddress[] = $address->toArray();
}
#displaying the array
echo '<pre/>';print_r($customerAddress );exit;

After getting the user’s address you will see something like this:

Array
(
    [entity_id] => 1
    [entity_type_id] => 2
    [attribute_set_id] => 0
    [increment_id] => 
    [parent_id] => 1
    [created_at] => 2013-12-05 14:28:40
    [updated_at] => 2013-12-05 16:14:13
    [is_active] => 1
    [firstname] => Daniel
    [lastname] => Halmagean
    [city] => New York
    [region] => New Jersey
    [postcode] => 123123
    [country_id] => RO
    [telephone] => 2342423434243
    [region_id] => 282
    [street] => my street name
    [customer_id] => 1
)

…first time posted on w3bdeveloper.com

by