• Resolved pb52

    (@paulbarrett1952)


    If a user is logged in you can prefill fields like name and email. Can you pull other details from the WordPress User database such as the address fields?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @paulbarrett1952 ,

    At the moment only name and email can be autofill for logged in users. But I will suggest Forminator’s Team to check if this can be improved and more user data added.

    kind regards,
    Kasia

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @paulbarrett1952

    I hope you are doing well.

    Could you try this code, shared by our developers?

    <?php
    
    add_filter( 'forminator_cform_render_fields', function( $wrappers, $form_id ){
    	// if( $form_id === 123 ){
    		if( is_user_logged_in() ){
    			$user = wp_get_current_user();
    			// https://developer.wordpress.org/reference/functions/wp_get_current_user/
    			// first name field.
    			$_REQUEST['first_name'] = $user->user_firstname;// $user->user_login;
    			// email field.
    			$_REQUEST['email'] = $user->user_email;
    			/** Address field */
    			// Address.
    			$address = get_user_meta( $user->ID, 'billing_address_1', true );
    			$_REQUEST['address'] = $address;
    			// City.
    			$city = get_user_meta( $user->ID, 'billing_city', true );
    			$_REQUEST['city'] = $city;
    			// State.
    			$state = get_user_meta( $user->ID, 'billing_state', true );
    			$_REQUEST['state'] = $state;
    			// Postcode.
    			$postcode = get_user_meta( $user->ID, 'billing_postcode', true );
    			$_REQUEST['postcode'] = $postcode;
    			// Country.
    			$country = get_user_meta( $user->ID, 'billing_country', true );
    			$_REQUEST['country'] = $country;
    		}
    	// }//End check form id.
    	return $wrappers;
    }, 10, 2 );

    Make sure to update the ID on // if( $form_id === 123 ){ and remove the comment if you would like to limit to a specific form,

    You can install it as a mu-plugin following the guide:
    https://premium.wpmudev.org/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    We also created a task to improve it on the future, but we can’t give an estimated time.

    Let us know if the solution worked for you.
    Best Regards
    Patrick Freitas

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prefilling Fields’ is closed to new replies.