0

I'm writing some magenta 1.9 codes for set existing customer address to set as default billing and shipping address

<?php $customerId = Mage::getSingleton('customer/session')->getCustomer();
$customer = Mage::getModel('customer/customer')->load($customerId->getId()); 
$data = array();

foreach ($customer->getAddresses() as $address){

$data = $address->toArray();
  if(trim($data['postcode']) !=''){
  $address->setIsDefaultBilling('1');
  $address->setIsDefaultShipping('1');
  $address->save();
break;
}
}
?>

But it doesn't seems works, anyone have idea to fix this please, Thank You

1 Answer 1

1

Try this code :

if(trim($data['postcode']) !='')
{
    $customerAddress = Mage::getModel('customer/address');
    $customerAddress->load(trim($data['id']); //ID means address Id
    $customerAddress->setIsDefaultBilling('1');
    $customerAddress->setIsDefaultShipping('1');
    $customerAddress->save();
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.