• Resolved pobacademynigeria

    (@pobacademynigeria)


    I want to:

    Customize the Tutor LMS student registration form ([tutor_student_registration_form]).

    Add these extra fields, with some being required:

    Phone Number (required)

    Billing/Residential Address (required)

    Personal or Business Website

    About Yourself/Business (required)
    Why are you purchasing our course? (required)

    ==
    I use this code in my code snippet function.php but it didn’t work


    // Show custom fields on Tutor LMS student registration form
    add_action('tutor_student_register_form_after', function () {
    ?>
    <p>
    <label for="phone_number">Phone Number (Preferably WhatsApp)*</label>
    <input type="text" name="phone_number" placeholder="e.g. +2348036411416" required>
    </p>
    <p>
    <label for="billing_address">Billing or Residential Address*</label>
    <input type="text" name="billing_address" placeholder="No. 4, XYZ Street, your state and country" required>
    </p>
    <p>
    <label for="website">Do you have a personal or business website?</label>
    <input type="url" name="website" placeholder="Enter your website URL (if any)">
    </p>
    <p>
    <label for="about_you">Tell Us About Yourself/Business*</label>
    <textarea name="about_you" placeholder="We’d like to know what your immediate goal is..." required></textarea>
    </p>
    <p>
    <label for="why_purchase">Why are you purchasing our course(s) and what is your immediate goal?*</label>
    <textarea name="why_purchase" placeholder="Tell us why you're here..." required></textarea>
    </p>
    <?php
    });

    // Validate the custom fields
    add_filter('tutor_student_registration_validation', function ($errors) {
    if (empty($_POST['phone_number'])) {
    $errors->add('phone_number', __('Phone Number is required.', 'tutor'));
    }
    if (empty($_POST['billing_address'])) {
    $errors->add('billing_address', __('Billing Address is required.', 'tutor'));
    }
    if (empty($_POST['about_you'])) {
    $errors->add('about_you', __('Tell Us About Yourself/Business is required.', 'tutor'));
    }
    if (empty($_POST['why_purchase'])) {
    $errors->add('why_purchase', __('Why are you purchasing this course? is required.', 'tutor'));
    }
    return $errors;
    });

    // Save the custom fields to user meta
    add_action('tutor_after_student_register', function ($user_id, $data) {
    if (!empty($_POST['phone_number'])) {
    update_user_meta($user_id, 'phone_number', sanitize_text_field($_POST['phone_number']));
    }
    if (!empty($_POST['billing_address'])) {
    update_user_meta($user_id, 'billing_address', sanitize_text_field($_POST['billing_address']));
    }
    if (!empty($_POST['website'])) {
    update_user_meta($user_id, 'website', esc_url_raw($_POST['website']));
    }
    if (!empty($_POST['about_you'])) {
    update_user_meta($user_id, 'about_you', sanitize_textarea_field($_POST['about_you']));
    }
    if (!empty($_POST['why_purchase'])) {
    update_user_meta($user_id, 'why_purchase', sanitize_textarea_field($_POST['why_purchase']));
    }
    }, 10, 2);

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Customise Tutor registration’ is closed to new replies.