how-to-delete-all-customers-in-woocommerce (1)

6 minutes

How to Delete All Customers in WooCommerce

Deleting all WooCommerce customers from your database is not as straightforward as it seems. Even though it can be done manually, for online stores with a large number of customers the application of such a method is slow and arduous. Thankfully, there are quite a few ways how we can delete WooCommerce customers. Let us take a look at the most common approaches.

Deleting All WooCommerce Customers Manually

If your WooCommerce online store has a relatively small number of customers, then manually deleting them is quite efficient.

Go to your WordPress dashboard and locate the Users tab. Click on it and you will be re-directed to the Users window.

WooCommerce delete users

Right above the user list, you will see different tabs for various user roles. Find the Customers tab and click on it. You will see a list with all WooCommerce customers registered on your WordPress database.

WooCommerce customers

By default, WordPress displays 20 users per page. If the number of customers in your case is higher, then locate the Screen Options tab in the upper right corner and click on it.

WordPress screen options

Set the Number of Items Per Page option accordingly, so it would display all of your customers on a single page. Click the Apply button afterward to save changes.

Pagination customers

You can select all customers instantaneously by ticking the checkbox underneath the Bulk Actions window. If you want to delete only specific customers, then you will need to tick each box manually.

Delete all WooCommerce customers

Now that you have selected all customers, click on the Bulk Actions window and select the Delete option. Click on the Apply button to confirm your selection.

delete all customers

You will be re-directed to the Delete Users window. It is just an extra step that you have to do in order to confirm the action. When deleting a user, any user, you should tread carefully. You delete any data associated with the user too, so, consequently, there might be cases when you remove something you might not want to. Anyways, click on the Confirm Deletion button.

WooCommerce customer deletion

Now all of your customers have been deleted and you can start afresh.

Deleting All WooCommerce Customers via SQL and WP-CLI

Usually, a WooCommerce online store has hundreds of customers, so deleting them manually can be incredibly time-consuming. With some knowledge in coding, you can quickly solve this issue via SQL queries or WP-CLI. We will take a look at 2 different cases concerning customer deletion and provide you with the necessary code.

Customers with 0 Orders

There are times when your database is full of registered WooCommerce customers that have not made a single order. This number of customers can reach thousands, in return, slowing down your website.

Login to your phpMyAdmin account. Before proceeding, confirm that the script will be run on the correct database. To ratify whether the correct database is loaded, look for the table wp_options and check if it has the correct URL for your website. Always backup your website before running any script! Otherwise, you may lose significant data or even render the website inaccessible. You should regularly take precautions when running advanced SQL queries.

SQL queries

Now that you have located the SQL panel, select the wp_posts table and paste the code below. If your database prefix is not wp_, then replace it with the prefix you are using. This piece of code will determine which customers have 0 orders and 0 posts. Press the Go button to execute the SQL statement.

SELECT * from wp_users where wp_users.ID not in (

SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user'

) AND wp_users.ID not in (

select distinct(post_author) from wp_posts

)

If the query is executed properly, then you will need to substitute SELECT * with DELETE in order to delete all WooCommerce customers with 0 orders. We have done it in your stead and can just copy the code below. Press the Go button to execute the SQL statement.

DELETE from wp_users where wp_users.ID not in (

SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user'

) AND wp_users.ID not in (

select distinct(post_author) from wp_posts

)

At last, all of your WooCommerce customers with 0 orders have been deleted. Now you should clear up user meta to get rid of any leftover data. In the same manner, paste the code below and press the Go button to execute the SQL statement.

delete from wp_usermeta where wp_usermeta.user_id not in (select ID from wp_users);

You can take a look at your WooCommerce user list to confirm whether or not all users have been deleted. If there are some inconsistencies, then, most likely, you have forgotten to swap the database prefix wp_ with whatever your database uses.

Deleting All Customers

Honestly, deleting all WooCoomerce customers via SQL is rather complicated. With an improper query, you run the risk to delete all users, and the query in itself is very long and complex. We recommend using WP-CLI for this task. You can take a look at their documentation here on how to set up WP-CLI command-line interface.

WP-CLI delete customers

Take a look at the command below. It is a simple one-line command utility for deleting all WooCommerce customer data. Additionally, you will not have to worry about damaging your database.

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

Keep in mind that this command deletes only customers, all of the data concerning their orders has remained intact. If you want to delete all WooCommerce orders too, then take a look at our article here.

Deleting All WooCommerce Customers via Plugins

If you are not savvy with coding and databases in general, then consider using plugins. Unfortunately, there are not many plugins that can delete all WooCommerce customers and their corresponding data. Although there are plugins that reset databases, not many of them have functionality for this specific task. Let us take a look at 3 popular plugins that can be used to delete all WooCommerce customers.

WP Reset. The most popular plugin for resetting sites databases to the default installation values without modifying files. It is a fast and efficient way of targeting specific data and removing it. With multiple fail-safe mechanisms integrated into the plugin, you will be able to restore any data you have accidentally deleted. We advise you to carefully take a look at the documentation in order to understand how to select and target the data you desire.

Store Toolkit for WooCommerce. This plugin includes a growing set of commonly-used WooCommerce administration tools, mainly, aimed at web developers and store maintainers. With a large set of maintenance/debugging/clearing tools at your disposal, you will be able to delete any data concerning WooCommerce.

Smart Manager for WooCommerce. For the most part, this plugin is used to increase WooCommerce functionality and add additional tools for managing your store, but it can be used to clear your database from unnecessary customer data. The plugin has a free(lite) version and a paid one.

Final Words

As you can see, managing WooCommerce online store requires some technical knowledge. Even a seemingly simple task, like deleting all customers, can turn out to be challenging. The aforementioned solutions will help with accomplishing this task. Again, be careful when running SQL queries, double-check the syntax and always back up your database. We wish you a bug-free journey through the world of e-commerce and stay tuned for more articles!






0/5


(0 Reviews)

Alexey Seryapin

Alexey is a WordPress wizard with 10+ years of experience as a lead developer, He has launched 500+ WordPress websites and 100+ WooCommerce shops.

KEEP YOUR ONLINE SHOP SAFE WooCommerce Maintenance Service

Save 17% with our Annual pricing plan.

Has your website been hacked?

WordPress Malware Removal Service

We will fix any WordPress hack and make your website hackproof.

Related Posts

woocommerce-to-facebook-shop

WooCommerce to Facebook Shop

how-to-translate-woocommerce-into-your-native-language

How to translate WooCommerce into your native language?

how-to-refund-in-woocommerce

How to Refund in WooCommerce

5-reasons-why-you-need-security-testing-for-your-software

5 Reasons why you need Security Testing for your Software