WooCommerce WordPress WP-CLI

How to Bulk Delete all WooCommerce Customer Accounts

The following WP-CLI command is a really easy way to delete all existing WooCommerce customer accounts on a WordPress website:

wp user list --field=ID --role=customer | xargs wp user delete --yes

And the best part: all of the information from the customers’ existing orders remained in-tact as well!

WordPress WP-CLI

Importing 1100 users into WordPress from a CSV file using WP-CLI

The Problem

A spreadsheet of ~1100 people (name, email address, etc) that needs to be imported into a WordPress site as users:

User Import CSV File
The User Import CSV File

I tried several user import plugins, but I had trouble with some users not importing (duplicate email addresses and/or usernames), and the plugins I tried didn’t make it easy to see which accounts were failing to import and why.

The import process via the WordPress dashboard was also encountering timeout problems due to the large amount of data being imported.

The Solution

WP-CLI’s user import command available to the rescue!

I used the following command to import the 1100+ user accounts:

wp user import-csv --skip-update user-import.csv

Note: this command skips user accounts that already exist because I included the --skip-update flag.

The output of this command made it very easy to identify the lines/users that were failing to import due to their email addresses already exist.

Bulk Deleting all Subscriber Accounts

I fixed up the duplicate data in the CSV file, and then used the following command to delete the imported user accounts before attempting the import again:

wp user list --role=subscriber --field=ID | xargs wp user delete --yes

Note: this command deletes ALL existing subscriber user accounts.

Once the imported accounts were deleted, I was able to retry the import using the command above.

Using WP-CLI for this ended up working great, and the import process was much quicker than using a plugin because I didn’t have to worry about server timeouts and other problems.

Are you using WP-CLI?

If you’re not already using WP-CLI, be sure to check out my previous presentation.

Development Events Meetups Presentations WordPress WP-CLI

Command Line WordPress with WP-CLI

Tonight at the WordPress Melbourne User Group September 2013 Meetup, I gave a presentation titled Command Line WordPress with WP-CLI.



Command Line WordPress with WP-CLI from James Collins


Are you already using WP-CLI? If so, please let me know what your favourite WP-CLI command is.

If not, I suggest you go to and give it a try 🙂