Appointments + default e-mails aren't descriptive nor helpful.

Customize E-mail Notifications from Appointments +

WPMU DEV’s Appointments + is a great scheduling plugin for WordPress. Though this plugin is not specifically intended for booking reservations (WPMU DEV is developing a plugin specific for booking), this does just fine with a few customizations.

One of the customizations that I thought would be really helpful was to customize the notification e-mail that service providers and administrators get whenever someone makes an appointment or books a reservation. By default, this is the e-mail message that providers get:
Appointments + default e-mails aren't descriptive nor helpful.
Not very detailed nor very descriptive, is it? Thanks to the wonders of PHP, we can customize the notification e-mail to have the customer’s name, the appointment time, the customer’s phone number, and more.

For my purposes, I only needed the name, phone number, appointment time, and the customer’s optional note. You can include the customer’s e-mail address as well.

When you have Appointments + installed, open up appointments.php. The function for the e-mail notification is around line 10251. The first part is pulling the appropriate row from the SQL table; the second part is for the Administrator’s e-mail and the last part is for the Provider’s e-mail.

Get and Declare the Appropriate Variables

Here is the original code that declares the function and lets us pull variables from the database:

	
/**
* Send notification email
* since 1.0.2
*/

function send_notification( $app_id ) {

	if ( !isset( $this->options["send_notification"] ) || 'yes' != $this->options["send_notification"] )

		return;

	global $wpdb;

	$r = $wpdb->get_row( "SELECT * FROM " . $this->app_table . " WHERE ID=".$app_id." " );

For us to be able to use customer’s information in the e-mail notifications, we need to add the following code after the above block:

$customer_name = $r->name;
$customer_phone = $r->phone;
$customer_email = $r->email;
$customer_time = date(  "F j, Y, g:i a", strtotime( $r->start ));
$customer_note = $r->note;

Now comes the fun part!

Admin E-mail Notification

Original Code:

			
$admin_email = apply_filters( 'app_notification_email', $admin_email, $r );

$body = sprintf( __('The new appointment has an ID %s and you can edit it clicking this link: %s','appointments'), $app_id, admin_url("admin.php?page=appointments&type=pending") );

$mail_result = wp_mail(

	$admin_email,

	__('An appointment requires your confirmation', 'appointments'),

	$body,

	$this->message_headers( )

	);

Customized code where we use our customer variables:

$admin_email = apply_filters( 'app_notification_email', $admin_email, $r );

$body = sprintf( __('Hello! %s wants to book a reservation at %s. Please contact them at %s. Further Notes: %s. Please edit or confirm the reservation here: %s ','appointments'), $customer_name, $customer_time, $customer_phone, $customer_note, admin_url("admin.php?page=appointments&type=pending") );

$mail_result = wp_mail(

	$admin_email,

	__('Your Custom Email Subject', 'appointments'),

	$body,

	$this->message_headers( )

	);

As you can tell, we use %s as a placeholder for the variables that get declared further down in that line of code.

Provider E-mail Notifications

Now that we’ve done the admin e-mails, the provider’s e-mails are basically the same. Here is the original:

// Also notify service provider if he is allowed to confirm it

if ( $r->worker &&  $admin_email != $this->get_worker_email( $r->worker ) && isset( $this->options['allow_worker_confirm'] ) && 'yes' == $this->options['allow_worker_confirm'] ) {

$mail_result = wp_mail(

	$this->get_worker_email( $r->worker ),

	__('An appointment requires your confirmation', 'appointments'),

	sprintf( __('The new appointment has an ID %s and you can confirm it using your profile page.','appointments'), $app_id ),

	$this->message_headers( )

	);

	if ( $mail_result && isset( $this->options["log_emails"] ) && 'yes' == $this->options["log_emails"] )

	$this->log( sprintf( __('Notification message sent to %s for appointment ID:%s','appointments'), $this->get_worker_email( $r->worker ), $app_id ) );

}

And here is the custom code:

	
// Also notify service provider if he is allowed to confirm it

if ( $r->worker &&  $admin_email != $this->get_worker_email( $r->worker ) && isset( $this->options['allow_worker_confirm'] ) && 'yes' == $this->options['allow_worker_confirm'] ) {

	$mail_result = wp_mail(

	$this->get_worker_email( $r->worker ),

	__('Your Custom Email Subject', 'appointments'),

	sprintf( __('Hello! %s wants to book a reservation at %s. Please contact them at %s. Further Notes: %s. Please edit or confirm the reservation here: %s','appointments'), $customer_name, $customer_time, $customer_phone, $customer_note, admin_url("admin.php?page=appointments&type=pending") ),

	$this->message_headers( )

	);

	if ( $mail_result && isset( $this->options["log_emails"] ) && 'yes' == $this->options["log_emails"] )

	$this->log( sprintf( __('Notification message sent to %s for appointment ID:%s','appointments'), $this->get_worker_email( $r->worker ), $app_id ) );

}

With these customizations, you can make the Appointments + Email Notifications much more useful and more friendly for your clients and your clients’ employees.

0 comments on “Customize E-mail Notifications from Appointments +Add yours →

Leave a Reply