Magento – Delete a Customer Programmatically

customer

How can I delete a customer in magento by refering using its object from Mage::getModel("customer/customer") ?

I already researched in google and with the bad luck I found nothing.

Best Answer

If you want to delete the customer with some code that runs from the admin area, this should be enough:

$id = 5;//replace with desired id
//or
//$customer = Mage::getModel('customer/customer')->loadByEmail($email);
$customer = Mage::getModel('customer/customer')->load($id);
$customer->delete();

If you want to delete the customer from the frontend area you need to wrap the code above in this:

Mage::register('isSecureArea', true);
//code from above goes here
Mage::unregister('isSecureArea');
Related Topic