There may be times where you want to clean up your WordPress database of WooCommerce customers. For example if your website is the unfortunate target of a spam attack where hundreds, or maybe thousands, of spam user accounts get created. You probably don't want to go to your users page and have 95% of the users be spam users.
The code below can be run to clean up those users. Just create a PHP file in the root of your WordPress directory and put this code there. I usually call it something like prune_customers.php
.
prune_customers.php
Then you can run the code from your browser or from the command line. I will usually execute the PHP file from the command line by making sure I'm in the same directory as the file I just created and running the following.
bash
If you would rather run the code in the browser you can visit https://yourwebsite.com/ prune_customers.php (or whatever name you gave your file). This will run the code in that file. Running the code this way may result in your browser timing out, depending on how many users there are that need deleted.
Once you finish deleting all the users I would make sure to delete this file to make sure it doesn't get run by accident later on.
Was this post helpful?