Email the Shop When a New Customer Registers
Sends the shop owner a short email whenever someone creates a customer account, at checkout or on the My Account page.
Opens WPIDE on
Code
$wpide_new_customer_to = ''; // Recipient; empty uses the admin email.
add_action( 'woocommerce_created_customer', function ( $customer_id ) use ( $wpide_new_customer_to ) {
$user = get_userdata( $customer_id );
if ( ! $user ) {
return;
}
$mailer = WC()->mailer();
$body = sprintf(
'<p>%1$s</p><p><a href="%2$s">%3$s</a></p>',
esc_html( sprintf( 'A new customer account was created: %1$s (%2$s).', $user->display_name, $user->user_email ) ),
esc_url( admin_url( 'user-edit.php?user_id=' . $customer_id ) ),
esc_html( 'View customer' )
);
$mailer->send( $wpide_new_customer_to ? $wpide_new_customer_to : get_option( 'admin_email' ), sprintf( '[%s] New customer registered', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ), $mailer->wrap_message( 'New customer', $body ) );
} );
Notes
Set $wpide_new_customer_to to send it to someone other than the site admin.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.