Magento 1.9 – How to Get List of Billing and Shipping Addresses Based on Customer ID

billing-addresscustomercustomer-addressmagento-1.9shipping-address

Please, can someone tell me, how to get list shipping addresses and billing addresses the specific customer by customer id in Magento 1.9?

Thanks.

Best Answer

Try following way:


$customerId = 2;
$customer = Mage::getModel('customer/customer')->load($customerId);
$defaultBilling  = $customer->getDefaultBilling();
$defaultShipping = $customer->getDefaultShipping();

$allAddress = Mage::getModel('customer/address')->getCollection()->setCustomerFilter($customer);

foreach ($allAddress as $address) {
    if($defaultBilling == $address->getId()) {
        // its customer default billing address
    } else if($defaultShipping == $address->getId()) {
        // its customer default shipping address
    } else {
        // its customer other address that saved
    }
}