How do I populate custom field with current user role in Woocommerce [closed]

wp_get_current_user() returns a user object. You can’t output objects directly.

Proceed by getting the users roles like $roles = (array)$user->roles;. Note that this returns an array though, so you will probably want to use the first element with $roles[0].

Your code might look like this (untested):

function onboarding_update_fields( $fields = array() ) {
   $user = wp_get_current_user();
   $roles = (array)$user->roles;
   $fields['customertype'] = $roles[0];
   return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'onboarding_update_fields' );

Additionaly, you might want to check if the user is logged in, otherwise there might not be a user and role available.

WordPress Code Reference articles: wp_get_current_user, User object.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)