4

I want to check whether the Given address is Default Shipping or Billing for the Customer address, i have the address id. Can anyone please help me on this.

2 Answers 2

8
$addressId = your id here;
$address = Mage::getModel('customer/address')->load($addressId);
$customer = $address->getCustomer();
$defaultBilling = $customer->getDefaultBillingAddress();
if ($defaultBilling) {
    if ($defaultBilling->getId() == $addressId) {
        //is default billing
    } else {
        //is not default billing
    }
} else {
    //is not default billing
}

DO the same for shipping address. Just replace billing with shipping

2
  • 1
    Sorry, Marius, you missed the default shipping address part.... May 30, 2016 at 7:29
  • 1
    @AnnaVölkl. I thought it was obvious to transform billing into shipping, but you are right.
    – Marius
    May 30, 2016 at 7:47
4

check the below code:

<?php 

$customerAddressID = '24'; // your customer address id
$customerID = '1';
$customer = Mage::getModel('customer/customer')->load($customerID);

$defaultBilling  = $customer->getDefaultBillingAddress();
$defaultShipping = $customer->getDefaultShippingAddress();

if ( ! $defaultBilling ) {
    $def_billing = 0;
} else { 
    $def_billing = $defaultBilling->getData('entity_id');
}   

if ( ! $defaultShipping ) {
    $def_shipping = 0;
} else { 
    $def_shipping = $defaultShipping->getData('entity_id'); 
}

if(($customerAddressID == $def_billing) || ($customerAddressID == $def_shipping))
{
    // your address is default billing or shipping address
}
2
  • Thanks for the Answer Manashvi. I tried the above answer it worked.
    – user2520
    May 30, 2016 at 7:30
  • do consider the order of answers.!! and whether the answer fulfills all your queries May 30, 2016 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.