Managing your WooCommerce store involves numerous tasks, and one of those tasks is maintaining a clean database. Over time, stores accumulate customers who have never placed an order. While these inactive accounts don’t generate revenue, they still take up space in the database. As the number of such users grows, it can lead to database bloat and slow down your WooCommerce site.
To improve your WooCommerce store’s performance, it’s essential to identify and remove these inactive customers. One effective approach is to create a custom admin page that lists and safely deletes customers with zero orders.
On the contrary, if you’re managing a busy store with thousands of orders, a tool like Flexi Archiver can help archive old order data and improve overall site performance.
Solution: Delete WooCommerce Customers With Zero Orders
This code creates a new “Cleanup Customers” page under the Users menu in the WordPress admin dashboard. It allows administrators to identify WooCommerce customers with 0 orders and safely delete them in bulk.
add_action('admin_menu', 'ts_cleanup_page');
function ts_cleanup_page() {
add_users_page(
'Cleanup Customers', // Page title
'Cleanup Customers', // Menu title
'manage_options', // Capability
'cleanup-customers', // Menu slug
'ts_cleanup_customers_page' // Function to display the page
);
}
function ts_cleanup_customers_page() {
if ( ! current_user_can('manage_options') ) {
wp_die('Insufficient permissions');
}
echo '<div class="wrap"><h1>Cleanup Customers Page</h1></div>';
echo '<p>Use this page to manage customers. You can view all customers with no orders here.</p>';
// Fetch all customers
$customers = get_users([
'role' => 'customer',
'fields' => ['ID', 'user_login', 'user_email']
]);
// Filter customers with no orders
$no_orders_customers = [];
foreach ($customers as $user) {
$customer_orders = wc_get_orders([
'customer' => $user->ID,
'limit' => 1, // Only check if at least 1 order exists
]);
$has_order = ! empty($customer_orders);
if ( ! $has_order ) {
$no_orders_customers[] = $user;
}
}
// Show preview table
echo '<h2>Customers With No Orders</h2>';
if ( count($no_orders_customers) ) {
echo '<table class="widefat"><thead><tr><th>ID</th><th>Login</th><th>Email</th></tr></thead><tbody>';
foreach ( $no_orders_customers as $user ) {
echo '<tr>';
echo '<td>' . esc_html($user->ID) . '</td>';
echo '<td>' . esc_html($user->user_login) . '</td>';
echo '<td>' . esc_html($user->user_email) . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
// --- HANDLE FORM SUBMISSION ---
if ( isset($_POST['ts_confirm_delete']) ) {
// Verify nonce for security
check_admin_referer('ts_cleanup_action', 'ts_cleanup_nonce');
$deleted_count = 0;
foreach ( $no_orders_customers as $user ) {
wp_delete_user($user->ID);
$deleted_count++;
}
echo '<div class="notice notice-success"><p>Deleted ' . esc_html($deleted_count) . ' customers with no orders.</p></div>';
}
// --- ADD FORM ---
echo '<form method="post">';
wp_nonce_field('ts_cleanup_action', 'ts_cleanup_nonce'); // Nonce field for security
echo '<p>';
echo '<input type="submit" name="ts_confirm_delete" class="button button-primary" value="Delete All Customers" onclick="return confirm(\'Are you sure you want to delete all customers with no orders?\');">';
echo '</p>';
echo '</form>';
} else {
echo '<p>No customers without orders found.</p>';
}
}
Output
When the admin opens the Cleanup Customers page from Users → Cleanup Customers, they see a list of customers who have never placed an order, including their ID, username, and email.

If customers with zero orders are present, a “Delete all customers” button is displayed. Clicking this button triggers a confirmation prompt, ensuring the admin wants to proceed before permanently deleting users.

If there are no customers with 0 orders, the page shows a friendly message:
“No customers with 0 orders found.”

Before deleting customer or order data, it’s important to understand how WooCommerce handles it behind the scenes. Removing orders or customers incorrectly can affect your store’s database and overall performance.
To learn more about what actually happens when orders are deleted and how to keep your store data safe, check out our detailed guide on what happens when you delete an order in WooCommerce?

2 thoughts on “How To Delete WooCommerce Customers With Zero Orders?”
This brought in all my customers
Hi Justin,
Please make sure to test the code with the latest WooCommerce version (10.1.2). I’ve also updated the code to use WooCommerce’s built-in function for checking customer orders, which now makes it more accurate and compatible with all WooCommerce versions.