php – How do I populate custom field with current user role in Woocommerce


I am trying to populate a custom field called Customer Type in checkout with the current user role. I tried the below in my functions.php of my child theme and thought it would work but it does nothing. Can anyone tell me what I might be doing wrong?

$user = wp_get_current_user();
function onboarding_update_fields( $fields = array() ) {

   $fields['customertype'] = $user;

return $fields;

add_filter( ‘woocommerce_checkout_fields’, ‘onboarding_update_fields’ );

Jay 2 years 2021-04-11T18:38:45-05:00 0 Answers 0 views 0

Leave an answer