I'm trying to populate an address field with the billing address information from the current user's data. I do not know what I've done wrong. Also, if I check the box in the form to allow for dynamic population, how do I set up the hooks to get the data I want?
I've created the following code:
add_action("gform_pre_submission_2", "mwn_gform_pre_submission_2");
function mwn_gform_pre_render_2($form){
$current_user = wp_get_current_user();
$user_data = get_user_meta($current_user->ID );
foreach($form["fields"] as &$field)
switch($field["id"]){
case 27:
foreach($field["inputs"] as &$input) {
switch($input["id"]){
case 27.1:
$input["value"] = $user_data["billing_address_1"][0];
break;
case 27.2:
$input["value"] = $user_data["billing_address_2"][0];
break;
case 27.3:
$input["value"] = $user_data["billing_city"][0];
break;
case 27.4:
$input["value"] = $user_data["billing_state"][0];
break;
case 27.5:
$input["value"] = $user_data["billing_postcode"][0];
break;
default:
break;
}
}
break;
default:
break;
}
return $form;
}