Created
February 9, 2017 18:57
-
-
Save joshuadavidnelson/a8bdc46aa49493e61a01b25ba8b7390a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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