Support » Developing with WordPress » how to customize new user email notification when the user created by admin

  • Hey there,
    I want to send a welcome email to the new customer that I created manually in the admin area.
    I tried add_filter with this hook (wp_new_user_notification_email) but it doesn’t work because it just works when users register themselves via the registration form.
    After that, I disabled “Send the new user an email about their account.” option in admin add new user form, and tried to write my own function with this hook (user_register) like this:

    function my_new_user_notification($user_id){
    	$new_user = get_userdata($user_id);
    	if(in_array( 'Customer', (array) $new_user->roles )){
    		$email_headers = 'From: <';
    		$email_to = $new_user->user_email;
    		$email_subject = sprintf("Welcome to example! Your account has been created successfully.");
    		$email_message = sprintf("\r\nHi there,\r\n
    		Here is your login information, so please markup this email:\r\n");
    		$email_message .= sprintf("Username: %s\r\n", $new_user->user_login);
    		$email_message .= sprintf("Email: %s\r\n", $new_user->user_email);
    		wp_mail($email_to, $email_subject, $email_message, $email_headers);
    add_action('user_register', 'my_new_user_notification');

    But also this one doesn’t work, even when I remove if(in_array( 'Customer', (array) $new_user->roles )).

    WP Guys Help me please to solve it. I want to send a custom email to new customers that I create them manually in the admin area.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.