Auto populate post code in my booking process


I've enabled extra fields in my booking process. Mainly the post code / zip code. It's a mandatory field as I need to know the location of the client

This is also a mandatory field when a user signs up to my website. How do I auto populate that field in the appointments booking page. All the other fields populate except that one :slight_frown:

Thanks for help!

  • Michael Bissett
    • Recruit

    Hey @Kieran, hope you're doing well this evening! :slight_smile:

    You're wanting to auto-populate the field for logged in members, right?

    This sounds like something that I'll have to call in our SLS staff for, as this requires more technical expertise than what I can presently provide.

    How's the start of the week been treating you? :slight_smile:

    Kind Regards,

  • Kieran
    • The Crimson Coder

    Hi Jose,

    I've not really sorted out the sign up section yet which might be part of the problem. I'm trying Cimy User Extra Fields along with Theme My Login.

    I have the additional fields add on activated in Appointments + to take the post code and it's stored in my user account section in the shipping and billing part. It's also stored as an extra field via the plug in CIMY User Extra Fields.

    Where does Appointments+ pull the data from when it pre-populates the appointments booking form. I'm open to changing things

    Thanks for the help

  • Jose
    • Bruno Diaz

    Hey there @Kieran,

    Hope you are doing great!

    Sorry for the delay here, had a bunch of work lately :slight_frown:

    There are good news :slight_smile:, I made a customization of the Additional Fields add-on for you.

    Use the attached .php file to replace this one:

    How would it work?
    Well, when the add-on shows the additional fields, it will try to get the default value from the current user metadata.
    The metadata key should be the concatenation of 'app_' + the clean name of the additional field: 'app_' . $clean

    foreach ($fields as $field) {
    			$label = esc_html($field['label']);
    			$clean = $this->_to_clean_name($label);
    			$id = "appointments-{$clean}" . md5(serialize($field));
    			$type = esc_attr($field['type']);
                            $user_meta_value = get_user_meta( $current_user->ID, 'app_' . $clean, true );//This is the important part. 
                            $value = $user_meta_value ? $user_meta_value : ('checkbox' == $type ? 1 : '');
    			$form .= "<div class='appointments-field appointments-{$clean}-field'>" .
    				'<label for="' . $id . '"><span>' . $label . '</span></label>' .
    				"<input type='{$type}' id='{$id}' class='appointments-field-entry appointments-{$clean}-field-entry' data-name='{$clean}' value='{$value}' />" .

    Then, you only need to sort your registration process and save the ZIP Code as user metadata. In this case, the additional field clean name would be something like 'zipcode', therefore the key name would be 'app_zipcode'.

    This is how you would set the value in the registration process:

    update_user_meta($user_id, 'app_zipcode', $zipcode_value);

    Please keep me posted on how it works. :slight_smile:


  • Kieran
    • The Crimson Coder

    Hi Jose,

    Was just about to look at this! Sorry for not being in touch earlier. I noticed the new version of Appointments+ seems to have an update to get it working

    However unfortunately it isn't working for me :slight_frown: I've not tried your attachment yet though I just assumed the new version of Appointments would automatically work.

    Will try and take a closer look tomorrow


  • Michael Bissett
    • Recruit

    Hey @Kieran! :slight_smile:

    The patch that @Jose had provided earlier was included in version 1.4.5, so you shouldn't need to replace the file if you're running version 1.4.6.

    However, I would like to ask, what's the site you're testing this with? The one that's attached to this support ticket is presently running version 1.4.4 of Appointments+.

    Please advise,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.