Populate an Additional filed in class_app_shortcodes.php

Hi,

I have created an additional field in the admin. settings called Membership Number. This field now appears in the Confirmation page. All good so far!!!

In my Class_app_shortcodes.php I have declared the following variable

$membership_no= get_user_meta( $current_user->ID, 'membership_number', true );

I wish to populate the Additional Field with this value but the problem is how? I don't see the custom field in Class_app_shortcodes.php obviously as I guess it is created in the following: apply_filters( 'app_confirmation_fields', $ret );

Any help would be great!!

Thank you

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hey there, Ellis!

    I'm testing this on my site right now, let me make sure we're on the same page.

    Did you activate the "Additional Fields" add on, or are you doing this strictly with code?

    I'm at the same stage you are right now, I got the new field added in the settings, but it's not appearing on the Make An Appointment form or in the My Appointments table.

  • Ellis
    • New Recruit

    Yes activate the "Additional Fields" add on. The field appears in the Make An Appointment confirmation page without doing anything.

    To add the field to My Appointments table I use this code:

    add_filter('app_all_appointments_column_name','incsub_appt_add_field_display_col_name');
    function incsub_appt_add_field_display_col_name($head_html){
    // Repeat the following line for headers/column names
    $head_html .= '<th class="all-appointments-status">' . __('Anglers Mem. No.', 'appointments' ) . '</th>';

    return $head_html;
    }

    add_filter('app-shortcode-all_appointments-after_date','incsub_appt_add_field_display_field_value',99,2);
    function incsub_appt_add_field_display_field_value($x,$appointment){
    $appointments_data = get_option('appointments_data', array());

    $extra_html = '';
    $extra_fields = empty($appointments_data[$appointment->ID])? array(): $appointments_data[$appointment->ID];

    //repeat the following line for each extra fields, replacing hometeam with appropriate values
    $extra_html .= '<td>'.$extra_fields['membershipnumber'].'</td>';

    return $extra_html;
    }

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hello Ellis!

    I think I found the solution, or at least a much better explanation than I could personally give you, in this reply from my colleague @Jose: https://premium.wpmudev.org/forums/topic/customise-the-appointments-booking-form#post-651004

    This is the part I think is relevant to your project:

    Unlike default fields, custom fields defined in settings section are rendered into the DOM, so we can manipulate those easily from javascript.
    In your footer.php you can simply add the following code to define a default value attribute to the custom input field:

    <script type="text/javascript">
        jQuery(function($) {
            //replace the selector .appointments-customfield-field to match the class name in your html.
            var element = $('.appointments-customfield-field input');
            element.attr('value','Placeholder');
        });
    </script>

    Does this get you closer? If not, we'll keep looking. : )

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.