Tutor LMS :How to Add Custom Field in Registration Page

Custom Fields

If you are running an online course using fantastic LMS plugin -TutorLMS , it may just be your requirement to collect some more information at the time of registration of students for a course. For example, you may want to add a field for Phone Number or College Name etc.

If you desire to add such custom fields in the registration form for a course , it can be done easily by use of TWO code sets.

Code 1 in Function.php of Child Theme

add_filter('tutor_student_registration_required_fields', 'required_phone_no_callback');
if ( ! function_exists('required_phone_no_callback')){
    function required_phone_no_callback($atts){
        $atts['phone_no'] = 'Phone Number field is required';
        return $atts;
    }
}
add_action('user_register', 'add_phone_after_user_register');
add_action('profile_update', 'add_phone_after_user_register');
if ( ! function_exists('add_phone_after_user_register')) {
    function add_phone_after_user_register($user_id){
        if ( ! empty($_POST['phone_no'])) {
            $phone_number = sanitize_text_field($_POST['phone_no']);
            update_user_meta($user_id, '_phone_number', $phone_number);
        }
    }
}

Code 2: Add in Registration.php file

Following code should be inserted in the registration.php file and you should override it from your theme. The location of the file would be- yourtheme/tutor/dashboard/registration.php

<div class="tutor-form-row">

        <div class="tutor-form-col-12">
            <div class="tutor-form-group">
                <label>
                    <?php _e('Phone Number', 'tutor'); ?>
                </label>

                <input type="text" name="phone_no" value="<?php echo tutor_utils()->input_old('phone_no'); ?>" placeholder="<?php _e('Phone Number', 'tutor'); ?>">
            </div>
        </div>

    </div>

How to Add the Code ?

Best way is to first install a plugin called Snippet Code . You need to paste the above code in the Snippet Code or you can also paste directly in function.php. But only if you are using the child theme.

Demo Video for Adding Custom Field in Registration Page