Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Created February 9, 2017 18:57
Show Gist options
  • Save joshuadavidnelson/a8bdc46aa49493e61a01b25ba8b7390a to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/a8bdc46aa49493e61a01b25ba8b7390a to your computer and use it in GitHub Desktop.
<?php
// Route to user address from drop down list, update the '1' to the ID of your form – I am using this on 6 forms so I have removed the ID requirement
add_filter( 'gform_notification', 'welcome_email', 10, 3 );
function welcome_email( $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 ];
}
// create a variable based upon the user ID
if( !empty( $user_id ) ) {
$welcome = 'Dear ' . get_the_author_meta( 'display_name', $user_id ) . ',';
}
// this appends the variable to the foot of the notification
$notification['message'] = $welcome . $notification['message'];
return $notification;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment