Auto populate post code in my booking process

Hi,

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!

  • Kieran

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

  • Jose

    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:
    wp-content/plugins/appointments/includes/addons/app-users-additional_fields.php

    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}' />" .
    			"</div>";
    		}

    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:

    Cheers,
    Jose

  • Kieran

    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

    Thanks
    Kieran

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.