Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace the notifcation 'to' email address for a gravity form (untested code, example for comment reply)
<?php
/**
* @link http://joshuadnelson.com/user-dropdown-list-custom-notification-routing-gravity-forms/#comment-2611
*/
add_filter( 'gform_notification_1', 'route_user_email_notification', 10, 3 ); // replace the '_1' with your form id
function route_user_email_notification( $notification, $form , $entry ) {
$location = '';
$service = '';
foreach( $form['fields'] as &$field ) {
// This singles out select fields, then says if the field doesn't have a "location" or "service" custom CSS class, to move onto the next one
// - be sure to place these custom CSS fields in your gravity form editor, or ustilize an admin label or other identification unique to that field
if( $field['type'] !== 'select' || ( strpos($field['cssClass'], 'location') === false && strpos($field['cssClass'], 'service') === false ) )
continue;
// get the field id
$field_id = (string) $field['id'];
if( strpos($field['cssClass'], 'location') === true ) { // for the location field
$location = $entry[ $field_id ];
} elseif ( strpos($field['cssClass'], 'service') === true ) { // for the services field
$service = $entry[ $field_id ];
}
}
// set the email address to send the email to
if( !empty( $location ) && !empty( $service ) ) {
// this is where you call your custom function to return an email address
$email_to = jdn_get_the_email_addresses( $location, $service );
}
// if we have a new email address(es), then replace the 'to' field with them
if ( !empty( $email_to ) && is_email( $email_to ) ) {
$notification[ 'to' ] = $email_to;
}
return $notification;
}
function jdn_get_the_email_addresses( $location, $service ) {
// query your database and return email address(es) based on criteria
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.