1

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.

5
$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

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

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
}
  • Thanks for the Answer Manashvi. I tried the above answer it worked. – user2520 May 30 '16 at 7:30
  • do consider the order of answers.!! and whether the answer fulfills all your queries – Manashvi Birla May 30 '16 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy