'Receive on admin email all data for the new user account

We added new fields with new variables for the registration form, and we want to receive in our email all the data in the fields listed for the new client account at the moment of the account creation.

add_action('woocommerce_created_customer', 
    'woocommerce_created_customer_admin_notification');

function woocommerce_created_customer_admin_notification($customer_id)
{
    wp_send_new_user_notifications($customer_id, 'admin');

}

The part of the code that I have attached to this email is only sending us the email and username of the account that has been created. However, we want to receive all the data as mentioned before.



Solution 1:[1]

/**
 * Filters the contents of the new user notification email sent to the site admin.
 *
 * @since 4.9.0
 *
 * @param array   $wp_new_user_notification_email_admin {
 *     Used to build wp_mail().
 *
 *     @type string $to      The intended recipient - site admin email address.
 *     @type string $subject The subject of the email.
 *     @type string $message The body of the email.
 *     @type string $headers The headers of the email.
 * }
 * @param WP_User $user     User object for new user.
 * @param string  $blogname The site title.
 */
$wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname );

Use this wp_new_user_notification_email_admin filter and add the details to the message parameter.

$wp_new_user_notification_email_admin['message'].= "Test data";

See below for an implementation sample.

add_action('login_init', 'set_wp_new_user_notification_email_admin_init');

function set_wp_new_user_notification_email_admin_init() {
    add_filter('wp_new_user_notification_email_admin', 'set_wp_new_user_notification_email_admin', 10, 3);
}

function set_wp_new_user_notification_email_admin($wp_new_user_notification_email, $user, $blogname) {
    $wp_new_user_notification_email['subject'] = sprintf('[%s] New user %s registered.', $blogname, $user->user_login);
    $wp_new_user_notification_email['message'] = sprintf("%s ( %s ) has registerd to your blog %s.", $user->user_login, $user->user_email, $blogname);

    return $wp_new_user_notification_email;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1