Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active March 12, 2021 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/984e18ea5a18522b2339022168824ccf to your computer and use it in GitHub Desktop.
Save xnau/984e18ea5a18522b2339022168824ccf to your computer and use it in GitHub Desktop.
Shows how to route the Participants Database signup notification email to a recipient based on a value in the submission
<?php
/*
* Plugin Name: Participants Database Custom Signup Email Recipient
* Version: 0.1
* Description: sets the signup notification email recipient based on a value in the signup submission
* Author: Roland Barker, xnau webdesign http://xnau.com
*
*/
class pdb_select_email_recipient {
/**
* @var string name of the selector used to determine the routing
*
* edit this to match the name of the selector you are using
*/
private $router = 'department';
/**
* initializes the class
*/
public function __construct()
{
add_action( 'pdb-before_signup_thanks', array( $this, 'assign_recipient' ) );
}
/**
* checks the submission to determine the recipient of the email
*
* @see https://xnau.com/work/wordpress-plugins/participants-database/participants-database-documentation/participants-database-api/#bst
*
* @param object $thanks
*/
public function assign_recipient( $thanks )
{
// get the value of the router field
$selection = $thanks->participant_values[$this->router];
// defaults to the notification recipient as defined in the email template
$recipient = $thanks->notify_recipients;
// choose the notification recipient according to the selection
switch ( $selection ) {
case 'sales':
case 'returns':
$recipient = 'Andrea Sales <andrea@xnaucorp.com>';
break;
case 'support':
$recipient = 'Jaime Support <support@xnaucorp.com>';
break;
case 'jobs':
$recipient = 'Gregory Jobs <jobs@xnaucorp.com>';
break;
}
// set the recipient of the signup notification
$thanks->notify_recipients = $recipient;
}
}
new pdb_select_email_recipient;
@xnau
Copy link
Author

xnau commented Mar 12, 2021

Check this article for the full run-down...

Sending a Signup Notification to a Custom Recipient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment