Last active
March 6, 2018 11:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.