Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Appointments +] - Send notifications for pending appointments
<?php
/*
Plugin Name: [Appointments +] - Pending notifications
Plugin URI: https://premium.wpmudev.org/
Description: Send notifications for pending appointments
Author: Panos Lyrakis @ WPMUDEV
Author URI: https://premium.wpmudev.org/
License: GPLv2 or later
*/
add_action( 'wpmudev_appointments_insert_appointment', function( $app_id ){
if( ! function_exists( 'appointments_get_appointment' ) ){
return;
}
$app = appointments_get_appointment( $app_id );
if( 'pending' != $app->status ){
return;
}
$appointments = appointments();
$service = appointments_get_service( $app->service );
$worker_name = 'Our team';
$customer_email = $app->get_customer_email();
$content = "<p>Hi {%USERNAME%}</p>";
$content .= "<p>You have booked an appointment for <strong>{%SERVICE_NAME%}</strong> on {%APP_DATE%} with {%WORKER_NAME%}. The appointment's price is $ {%APP_PRICE%} USD</p>";
if( $app->worker ){
$worker = appointments_get_worker( $app->worker );
$worker_name = $worker->get_name( 'display_name' );
}
$replacements = array(
'{%USERNAME%}' => $app->name,
'{%SERVICE_NAME%}' => $service->name,
'{%APP_DATE%}' => date( 'd, M Y H:i:s', strtotime( $app->start ) ),
'{%APP_PRICE%}' => $app->price,
'{%WORKER_NAME%}' => $worker_name
);
$subject = "You have a new appointment!";
$email_body = str_replace(
array_keys( $replacements ),
array_values( $replacements ),
$content
);
$mail_to = $customer_email = $app->get_customer_email();
add_filter( 'app-emails-content_type', 'wpmudev_app_html_email_headers', 20 );
wp_mail(
$mail_to,
$subject,
$email_body,
$appointments->message_headers()
);
}, 20 );
function wpmudev_app_html_email_headers(){
remove_filter( 'app-emails-content_type', 'app_html_email_headers', 20 );
return 'text/html';
}
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.