Home » Magento20 January 2016

Magento: Delete Customers Programmatically

Here is a quick code to delete customers programmatically in Magento. You can manually delete customers from customer admin grid. But, sometime you might need to do it automatically through code.

Here is the full code to do so. This code can be saved in a new file in your Magento root folder and then you can run it in browser.

In this code, I have selected customers created within a certain date range. And then deleted those selected customers individually.

Hope this helps.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Daniel Lewis

    This code helped me out, so thank you. As always make sure you have a backup before any of this is run, because I ran into a couple issues.

    There is a syntax error on line 26 above, I had to add a semicolon. The date range you specified above is in international format. It removed the wrong customers for me in US format – I suggest performing a “dry run” of this deletion by commenting the actual delete method until you review the customer ID’s found by the code. In any case, changing international to US date format helped me grab the correct customers, but the timezone appears to specify UTC when pulling customers for these dates, so make sure to double check your IDs before this is run.

    Thanks again for publishing this code – it helped me recover from a very bad namespace mining attack.