When someone registers on a normal WordPress site, the admin gets a New User Registration email. WooCommerce customer accounts are different: when a customer creates an account on the My Account page or during checkout, WooCommerce sends the customer a welcome email, but the site admin gets nothing. Shop owners who want to know about new customers right away have to check the Customers screen.
This snippet sends WordPress’ own New User Registration email to the site admin every time WooCommerce creates a customer account. The email contains the username and email address.
The snippet
<?php
/**
* Email the site admin when a customer account is created in WooCommerce:
* on the My Account page or during checkout.
*/
add_action( 'woocommerce_created_customer', 'dpc_wc_new_customer_admin_email' );
function dpc_wc_new_customer_admin_email( $customer_id ): void {
// 'admin' sends only the "New User Registration" email to the site admin, not a second email to the customer.
wp_send_new_user_notifications( (int) $customer_id, 'admin' );
}
Add it with Scripts Organizer
In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Everywhere, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty. Accounts are created on front-end pages, during checkout requests and in the REST API, so the code has to load everywhere.
The same code also works unchanged in a small plugin or an mu-plugin.
How it works
- WooCommerce creates every customer account with
wc_create_new_customer(), and that function fireswoocommerce_created_customerwith the new user ID. This covers the My Account form, Create an account at checkout, and the checkout block. wp_send_new_user_notifications()is the function WordPress uses after a normal registration. With'admin'as the second argument it sends only the admin email, so the customer does not get WordPress’ set-password email on top of the WooCommerce welcome email.- The email goes to the address in Settings → General → Administration Email Address.
Customise it
Send the notification to the shop manager instead of the site admin. WordPress passes the email through a filter before sending it, so add this below the snippet:
add_filter( 'wp_new_user_notification_email_admin', function ( array $email ): array {
$email['to'] = 'shop@example.com';
return $email;
} );
- Change the subject or text in the same filter:
$email['subject']and$email['message']are in the array too. - Accounts created by an admin under Users → Add New or WooCommerce → Customers do not go through
woocommerce_created_customer, so they do not send this email.
Gotchas
- Guest checkouts create no account and send no email. Only orders where the customer creates an account count.
- If emails from the site do not arrive at all, fix mail delivery first (an SMTP plugin or your host’s mail service). This snippet uses the normal
wp_mail(). - Plugins that create customers with their own code (some membership and B2B plugins) may skip
wc_create_new_customer(). Check with a test registration.
In the Scripts Organizer library Import it with one click from Scripts Organizer.