@mdmortis

Как заполнить $fields c помощью кода?

Есть код получения ролей:
function get_user_role($user_id) {
	global $wp_roles;
	$roles = array();
	$user = new WP_User( $user_id );
	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
	foreach ( $user->roles as $role )
		$roles[] .= translate_user_role($wp_roles->roles[$role]['name']);
	}
	return implode(', ',$roles);
}


и код вывода в шаблон:

$cur_user_id = get_current_user_id(); echo get_user_role( $cur_user_id );


Также есть код добавления поля на страницу "Оформление заказа":

add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields( $fields ) {
    $fields['billing']['billing_patronymic'] = array(
        'label'       => __('Отчество', 'woocommerce'), // Add custom field label
        'placeholder' => __('Отчество', 'woocommerce'), // Add custom field placeholder
        'required'    => false, // if field is required or not
        'clear'       => false, // add clear or not
        'type'        => 'text', // add field type
        'class'       => array('billing_patronymic'),   // add class name
        'priority'    => 10, // Priority sorting option
    );

    return $fields;
}


Подскажите, как заполнить поле $fields с помощью кода вывода роли в ? Все производится в functions.php
  • Вопрос задан
  • 57 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы