Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrky007/dc54bdf9133984ce3ddc80c44001bb08 to your computer and use it in GitHub Desktop.
Save mrky007/dc54bdf9133984ce3ddc80c44001bb08 to your computer and use it in GitHub Desktop.
WordPress / WooCommerce: notify user admin when user registers and send user meta values if needed
// Set content type to html if needed
function wp_set_content_type(){
return "text/html";
}
add_filter( 'wp_mail_content_type','wp_set_content_type' );
function admin_registration_email_alert( $user_id ) {
// Send to website admin
$to = get_option('admin_email');
// Get new user ID
$user = get_userdata( $user_id );
// Get new user email
$email = $user->user_email;
// Get custom user meta field (in my case it is a file url that was uploaded during registration)
$document = $user->attachment_url;
// Create message, I enabled wp_mail_content_type html, so i can put file url in href
$message = $email . ' has registered to your website. <a href=' .$document. '>Business certificate/diploma download</a>';
wp_mail( $to, 'New User registration', $message, $attachments );
}
add_action('woocommerce_created_customer', 'admin_registration_email_alert');
@mrky007
Copy link
Author

mrky007 commented Mar 6, 2018

This small snippet will send user registered notification to website admin along with custom user meta that was created during registration. In my case it is the url to the file that was uploaded during registration.

$document = $user->attachment_url; can be replaced with required user meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment