Hi @tonnick0033,
The user registration plugin has a specific field for the user name and display name. You can see it in this screenshot https://prnt.sc/FsyccppWDa1-.
If you include this field, users can enter usernames or display names of their choice. We have added these fields to user registration because users always want to show the profile names based on their needs.
If you’re already familiar with these features but still want to generate a user name from the first and last names, try the code below.
add_action( 'user_registration_after_register_user_action', 'ur_insert_nickname', 1, 3 );
function ur_insert_nickname( $valid_form_data, $form_id, $user_id ) {
$username = isset( $valid_form_data['user_login'] ) ? $valid_form_data['user_login']->value : '';
wp_update_user([
'ID' => $user_id, // this is the ID of the user you want to update.
'first_name' => $username,
'last_name' => $username,
]);
}
If you do not know where to custom code snippets on your site, please check this documentation https://docs.wpeverest.com/user-registration/docs/how-to-add-the-custom-code-snippet-on-your-site/.
Regards!