Saturday, May 28

How to get Customer Billing & Shipping Address in Magento

Here is the script to get Customer Billing and Shipping Address

$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping();
if ($customerAddressId){
       $address = Mage::getModel('customer/address')->load($customerAddressId);
}
else
{
 $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
}

Hope it Helps .. Thanks....

3 comments:

  1. Hi,
    i used this code in magento 1.6.1.0 in methods.phtml page, when i am trying to get the address, and i am placing order as guest and trying to get the address where we select payment method means in methods.phtml, its getting the address but its getting the address which i used for previous user.can you please tell me what problem exactly i have

    ReplyDelete
  2. It may be because of session problem. so it will get cleared once the customer placed the order. any how i will try to find the solution for this as soon as possible.

    ReplyDelete