Custom Field on Registration

If you want to add a new field on the registration page for Tutor LMS, please follow the snippet below.

In this sample, we have added a new field for phone number. Following this sample method, you can add as many custom fields as you want.

PHP Snippet

This one handles the functionality part. You have to paste this code on your child theme’s functions.php file. You can use a custom plugin if you want as well.

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);
        }
    }
}

HTML Snippet

This snippet will add the new field in HTML

   <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>

The HTML code should go 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

Here is a gist showing the entire file with the extra code in it. The Phone number field code is placed between line number 73 to 85.

Update from Profile Settings – Frontend

The data on profile settings is fetched through /tutor/templates/dashboard/settings/profile.php. So, you have to override this file from your theme as well. The code should be something like-

        <div class="tutor-form-row">
            <div class="tutor-form-col-4">
                <div class="tutor-form-group">
                    <label>
                        <?php _e('Document Number', 'tutor'); ?>
                    </label>
                    <input type="text" name="doc_number" value="<?php echo get_user_meta($user->ID, '_doc_number', true); ?>" placeholder="<?php _e('Document Number', 'tutor'); ?>">
                </div>
            </div>

See the new fields in the backend

The backend profile data is being served from the file located at /tutor/views/metabox/user-profile-fields.php. So, you can edit this file like-

<tr class="user-description-wrap">
		<th><label for="description"><?php _e('Document Number'); ?></label></th>
		<td>
			<input type="text" name="doc_number" id="doc_number" value="<?php echo get_user_meta($user->ID, '_doc_number', true); ?>" class="regular-text" />
		</td>
	</tr>
This change would be lost on Tutor LMS update. We will implement a better way to override this file very soon. As an alternative, you can use “User Meta Inspector” plugin to see the data from the backend.

Now, you’re done. If you need any help, feel free to send an email to support. Do not forget to mention your theme name when you email for support on this specific customization.

Was this helpful?