/**
* Change the sent to email address in the notification
*
* @author Joshua David Nelson, josh@joshuadnelson.com
**/
// Route to user address from drop down list, update the '1' to the ID of your form
add_filter( 'gform_notification_1', 'route_user_email_notification', 10, 3 );
function route_user_email_notification( $notification, $form , $entry ) {
foreach( $form['fields'] as &$field ) {
// Similar to above, find the right field
if( $field['type'] != 'select' || strpos($field['cssClass'], 'user-emails') === false )
continue;
// Pull out the user id selected, by the field id and the $entry element
$field_id = (string) $field['id'];
$user_id = $entry[ $field_id ];
}
// set the email address to send the email to
if( !empty( $user_id ) ) {
$email_to = get_the_author_meta( 'user_email', $user_id );
}
if ( !empty( $email_to ) && is_email( $email_to ) ) {
$notification[ 'to' ] = $email_to;
}
return $notification;
}