Получить текущую роль пользователя, используя следующую функцию
function get_current_user_role(){
$current_user = wp_get_current_user();
$roles = $current_user->roles;
return $roles[0];
}
РЕШЕНИЕ № 1
Передать ее woocommerce_form_field ($ key, $ args, $значение) функция, рассмотрите пример ниже,
$fields = iconic_get_account_fields();
$role = get_current_user_role();
foreach ($fields as $key => $field_args) {
if ($key == 'role') {
woocommerce_form_field($key, $field_args, $role);
} else {
woocommerce_form_field($key, $field_args);
}
}
РЕШЕНИЕ № 2
Сделайте модификацию функции, которой вы поделились, как показано ниже, я добавил 'значение'Аргумент.
function iconic_get_account_fields() {
return apply_filters('iconic_account_fields', array(
'first_name' => array(
'type' => 'text',
'label' => __('First Name', 'iconic'),
'hide_in_account' => true,
'hide_in_admin' => true,
'hide_in_checkout' => true,
'hide_in_registration' => false,
'required' => true,
),
'last_name' => array(
'type' => 'text',
'label' => __('Last Name', 'iconic'),
'hide_in_account' => true,
'hide_in_admin' => true,
'hide_in_checkout' => true,
'hide_in_registration' => false,
'required' => true,
),
'role' => array(
'type' => 'select',
'label' => __('Franking Machine Model', 'iconic'),
'hide_in_account' => false,
'hide_in_admin' => true,
'hide_in_registration' => true,
'hide_in_checkout' => true,
'options' => array(
'' => __('Select an option...', 'iconic'),
'example_1_customer' => __('Example 1', 'iconic'),
'example_2_customer' => __('Example 2', 'iconic'),
'example_3_customer' => __('Example 3', 'iconic'),
'other_customer' => __('Other', 'iconic'),
),
'value' => apply_filters('selectedrole','') // added new arg
),
));
add_filter('selectedrole', 'get_current_user_role');
Дайте мне знать, какая работа лучше для вас.