Question

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.

Was it helpful?

Solution

$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

OTHER TIPS

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top