Send Special email to Site Admin when a new appointment is created

Hi -
I am trying to send a special email to the administrator and other office staff when an appointment is scheduled on the website.

Could you please review the code below and tell me why this is not working or recommend what changes I can make to ensure this work.

Code:

add_action( 'app-appointment-appointment_created', 'send_email_admin_created' );
function send_email_admin_created( $additional, $insert_id, $post_id, $service, $worker, $start, $end ){
global $appointments;
global $wpdb;

$headers = array('Content-Type: text/html; charset=UTF-8');

$multiple_recipients = array(
$appointments->get_admin_email(),
'custom email address 1'
);
wp_mail(
$multiple_recipients,
'A new Appointment was created',
'The following new appointment was created by a user.

Name: '.$user_name.'
Date/Time: '.$start.'
Location: '.$worker,
$headers
);
}

Thanks
Vamsi

  • Nastia

    Hello @Vamsi Pulavarthi, I hope you are well today!

    Thank you for asking this question!

    Unfortunately, I'm not a code expert, I flag her one of our developers here to give some further direction on this. Please note that, developer response might be slower than the usual staff response, so we really appreciate your patience on this.

    Have a nice day and take care :slight_smile:

    Cheers,
    Nastia

  • Vamsi Pulavarthi

    Hi Nastia -
    Here's the script I wrote based on your posting in another post.

    add_action( 'app_confirmation_sent', 'app_confirmation_sent_cb', 99, 3 );
    function app_confirmation_sent_cb( $body, $r, $app_id ){
       global $appointments;
       global $wpdb;
    
       $sql = "SELECT * from " . $wpdb->prefix . "app_appointments where ID = '".$app_id."'";
       $app = $wpdb->get_row( $sql, OBJECT );
    
       $confirmationDateTime = mysql2date($appointments->datetime_format, $app->start);
       $confirmationClientName = $appointments->get_client_name( $app_id );
       $confirmationProviderName = $appointments->get_worker_name( $app->worker );
       $confirmationHeaders = array('Content-Type: text/html; charset=UTF-8');
       $confirmationTo = array(
            $appointments->get_admin_email(),
            'mycustomemail@email.com'
       );
    
       $confirmationEmailBody = 'The following new appointment was scheduled by the user. <br /><br />';
       $confirmationEmailBody .= 'Name: ' . $confirmationClientName . '<br />';
       $confirmationEmailBody .= 'Date: ' . $confirmationDateTime . '<br />';
       $confirmationEmailBody .= 'Location: ' . $confirmationProviderName;
    
        wp_mail(
    		$confirmationTo,
            'A new Appointment was scheduled',
    		$confirmationEmailBody,
    		$confirmationHeaders
        );
    }

    Thanks
    Vamsi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.