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
$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
-
1@AnnaVölkl. I thought it was obvious to transform billing into shipping, but you are right.– Marius ♦May 30, 2016 at 7:47
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.– user2520May 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