• Hello, I need to have additional fields like Country and City in the account page. I need to have logic here. If Country 1 – List of City 1 etc. How to set conditional parameters?
    Have code like this

    add_action('um_after_account_general', 'after_account_general_custom_fields', 100);
    function after_account_general_custom_fields()
    {
        $custom_fields = [
            'first_name' => [
                'title'    => 'Имя',
                'label'    => 'Ф.И.О.',
                'metakey'  => 'first_name',
                'type'     => 'text',
                'placeholder' => 'Иванов Иван Иванович',
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'phone_number' => [
                'title'    => 'Телефон',
                'label'    => 'Телефон:',
                'placeholder' => '380 (67) 303-15-39',
                'metakey'  => 'phone_number',
                'type'     => 'text',
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'birth_date' => [
                'title'    => 'Дата рождения',
                'label'    => 'Дата рождения:',
                'metakey'  => 'birth_date',
                'placeholder' => '31/03/2020',
                'format' => 'd mmm yyyy',
                'years_x' => 'past',
                'years' => 115,
                'range' => 'years',
                'type'     => 'text',
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'sex' => [
                'title'    => 'Пол',
                'label'    => 'Пол',
                'metakey'  => 'sex',
                'type'     => 'select',
                'options' => array('Мужской', 'Женский'),
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'rss' => [
                'title'    => 'RSS',
                'label'    => 'Получать сообщения по объявлениям на E-mail',
                'metakey'  => 'rss',
                'type'     => 'checkbox',
                'options' => [1],
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'country_main' => [
                'title'    => 'Country',
                'label'    => 'Страна',
                'metakey'  => 'country_main',
                'type'     => 'select',
                'options' => array('Украина' , 'Беларусь', 'Казахстан', 'Литва', 'Молдова', 'Россия'),
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
            ],
            'state_ua' => [
                'title'    => 'Country',
                'label'    => 'Область/Регион',
                'metakey'  => 'country_main',
                'type'     => 'select',
                'options' => array(
                    'Винницкая область',
                    'Волынская область',
                    'Днепропетровская область',
                    'Донецкая область',
                    'Житомирская область',
                    'Закарпатская область',
                    'Запорожская область',
                    'Ивано-Франковская область',
                    'Киевская область',
                    'Крым',
                    'Луганская область',
                    'Николаевская область',
                    'Одесская область',
                    'Полтавская область',
                    'Ровенская область',
                    'Сумская область',
                    'Тернопольская область',
                    'Харьковская область',
                    'Херсонская область',
                    'Хмельницкая область',
                    'Черкасская область',
                    'Черниговская область',
                    'Черновицкая область'),
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
                'conditional_action' => 'show',
                'conditional_field' => 'country_main',
                'conditional_operator' => 'equals to',
                'conditional_value' => 0
            ],
            'state_be' => [
                'title'    => 'Country',
                'label'    => 'Область/Регион',
                'metakey'  => 'country_main',
                'type'     => 'select',
                'options' => array(
                    'Брестская',
                    'Витебская',
                    'Гомельская',
                    'Гродненская',
                    'Минская',
                    'Могилёвская',
                    'Минск'),
                'required' => 0,
                'public'   => 1,
                'editable' => 1,
                'conditional_action' => 'show',
                'conditional_field' => 'country_main',
                'conditional_operator' => 'equals to',
                'conditional_value' => 1
            ]
    
        ];
    
        $fields = apply_filters('um_account_secure_fields', $custom_fields, um_user('ID'));
    
        UM()->builtin()->saved_fields = $fields;
        UM()->builtin()->set_custom_fields();
    
        $output = '';
        foreach ($fields as $key => $data) {
            $output .= UM()->fields()->edit_field($key, $data);
        }
        echo $output;
    }
    add_action('um_account_pre_update_profile', 'account_pre_update_profile_newsletter_subscription', 100, 2);
    function account_pre_update_profile_newsletter_subscription($changes, $user_id)
    {
        $field = array('first_name', 'birth_date', 'rss', 'phone_number', 'sex');
        foreach ($field as $value){
            if(isset($_POST[$value]) && $_POST[$value] != null){
                update_user_meta($user_id, $value, $_POST[$value]);
            }
        }
    
    };
  • The topic ‘Additional fields in account page’ is closed to new replies.