My Listing – Change Nicename During Registration And Edit

[themify_is_logged_in]

#### Register Profile ####

function registration_save( $user_id ) {
     
    if ( isset( $_POST[ 'display_name' ] ) ) {
         
        wp_update_user( array(
            'ID'            => $user_id,
            'user_nicename' => sanitize_user( $_POST[ 'display_name' ] ) 
        ) );
         
        update_user_meta( $user_id, 'nickname', $_POST[ 'display_name' ] );
    }
 
}
add_action('woocommerce_created_customer', 'registration_save', 10 , 1 );

#### Edit Profile ####
  
function edit_save( $user_id ) {
      
    if ( isset( $_POST[ 'account_display_name' ] ) ) {
          
        wp_update_user( array(
            'ID'            => $user_id,
            'user_nicename' => sanitize_user( $_POST[ 'account_display_name' ] ) 
        ) );
          
        update_user_meta( $user_id, 'nickname', $_POST[ 'account_display_name' ] );
    }
}
add_action( 'woocommerce_update_customer', 'edit_save', 10, 1 );

[/themify_is_logged_in]