• Resolved Xaltas

    (@zombieoutbreakresponse)


    I have a custom field in my registration form for an ID number, I also have a custom field in the user profile for that same ID number. I was wondering if it was possible to “link” these fields so that it’s automatically entered (like the name and email address) so my users aren’t having to enter it every time they register for an event (all my events are logged-in users only). If anyone has any experience with this, any help would be greatly appreciated!!

    Side note: the plugin I’m using to create the custom fields in the user profiles is User Registration by WPEverest.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author roundupwp

    (@roundupwp)

    Hey Xaltas,

    We actually had one of our paid users have a similar request. I can help get you pointed in the right direction and you should be able to connect the dots if you have some PHP knowledge or know someone with some PHP knowledge.

    Here is a snippet of code that will output all of the “keys” in the database for the user meta created by that plugin:

    function ru_user_registration_info( $form_id ) {
    if ( ! current_user_can( 'manage_options') ) {
    return;
    }
    $field_data = ur_get_form_fields( $form_id );

    echo '<div>';
    foreach ( $field_data as $field_key => $field_data ) {

    echo '<p>';
    echo '<strong>' . $field_data->general_setting->label . '</strong> - user_registration_' . $field_key;

    echo '</p>';
    }
    echo '</div>';

    }
    add_action( 'user_registration_before_registration_form', 'ru_user_registration_info', 10, 1 );

    Wherever you have a registration form it will output some info at the top of it for you to help you get the right meta key:

    Then using that meta key, you would change this code so that the event registration form prefills that info with whatever this user has entered for that field:

    function rtec_add_user_registration_field( $field_attributes ) {

    $user_meta_key = 'user_registration_example'; // replace example with the $field_key discovered above
    $user_meta = get_user_meta( get_current_user_id(), $user_meta_key, true );
    if ( isset( $field_attributes['other'] ) ) {
    $field_attributes['other']['default'] = $user_meta;
    }

    return $field_attributes;
    }
    add_filter( 'rtec_fields_attributes', 'rtec_add_user_registration_field', 10, 1 );

    The example above assumes you are using the “Other” field for event registration for this task.

    Hopefully this helps!

    – Craig

    Thread Starter Xaltas

    (@zombieoutbreakresponse)

    Thanks for the response, @roundupwp ! I’ve tried putting that snippet in my user-registration.php, and I’m not getting any meta info on my registration form. Is there a particular place I need to put that, or just anywhere with the other functions?

    Plugin Author roundupwp

    (@roundupwp)

    I suppose I should mention this is only visible to logged-in admin users. Are you logged-in as an admin user when viewing the user registration form? Otherwise, if you contact me here I can send you a .zip file to make this easier to make sure the code will apply correctly!

    https://roundupwp.com/support/

    Thread Starter Xaltas

    (@zombieoutbreakresponse)

    @roundupwp Yes I am logged in with admin (albeit, the first time I was trying logged out), but even with admin it does not appear to be showing any meta fields on that form page. I will go ahead and shoot you a contact for that Zip. Appreciate all the help!

    Plugin Author roundupwp

    (@roundupwp)

    This thread has been quiet for awhile. I’ll mark it as resolved but please let me know if you need more help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.