Can I change how booking times appear in confirmation emails?

My service providers travel to customers premises. In my confirmation email I include a note to warn that due to travelling time etc we may not arrive exactly on the appointment time but it doesn't stop people ringing up ten minutes after their appointment time asking why nobody has turned up.

Can I edit the php somewhere to make my confirmation emails display the start time as a one hour window instead of the actual start time? Eg 12:00 - 13:00 instead of just 12:00

    Hoang Ngo

    Hi @Michael,

    I hope you are well today.
    First, please add this code to your theme functions.php or use mu-plugins

    add_filter( 'app_confirmation_message', 'update_started_time_message', 10, 3 );
    function update_started_time_message( $message, $r, $app_id ) {
    	global $appointments;
    
    	$date = mysql2date( $appointments->datetime_format, $r->start ) . ' - ' . mysql2date( $appointments->datetime_format, date( 'Y-m-d H:i:s', strtotime( '+1 hour', strtotime( $r->start ) ) ) );
    
    	return str_replace( 'DATE_TIME_EX', $date, $message );
    }

    And the, in the WP Admin->Appointments->Settings, section Confirmation email Message, usually you will see a default text like this

    Dear CLIENT,
    
    We are pleased to confirm your appointment for SITE_NAME.
    
    Here are the appointment details:
    Requested service: SERVICE
    Date and time: DATE_TIME
    
    SERVICE_PROVIDER will assist you for this service.
    
    Kind regards,
    SITE_NAME

    The DATE_TIME will give you normal time, to update to your need, please use the DATE_TIME_EX. So the text should change to

    Dear CLIENT,
    
    We are pleased to confirm your appointment for SITE_NAME.
    
    Here are the appointment details:
    Requested service: SERVICE
    Date and time: DATE_TIME_EX
    
    SERVICE_PROVIDER will assist you for this service.
    
    Kind regards,
    SITE_NAME

    If you have any additional issues, please let us know and we'll be happy to help.

    Best regards,
    Hoang

    Michael

    Hi Hoang,

    Thanks very much for your reply. I have tried the code you kindly supplied me and although it works perfectly the formatting is not quite how I want it.

    With your code the DATE_TIME_EX is replaced with 12 Nov 13:00 - 12 Nov 14:00

    Ideally I would like it to be formatted 13:00 - 1400 on 12 Nov, is this possible?

    I also have an additional request which you may be able to help with. My business also has a text message gateway which we also use to confirm appointments. A member of the WPMU team previously supplied some code which we use for this which sends an additional email to our client via our SMS gateway. I wonder if you could suggest a modification to this code which would also change the appointment time to display 13:00 - 14:00 instead of just 13:00? Here is the code snippet

    <?php 
    
    add_action( 'app_confirmation_sent', 'app_confirmation_sent_sms', 20, 3 );
    function app_confirmation_sent_sms( $body, $r, $app_id ) {
    
    	$myphone = preg_replace('/[-\s.]+/', '', $r->phone);
    
    	wp_mail(
            	'' . $myphone . '@echoemail.net',
            	'',
            	'Booking confirmed, we have sent full details to ' . ( $r->email ) . ' Your appointment is at ' . date_i18n( get_option( 'time_format' ), strtotime( $r->start ) ) . ' on ' . date_i18n( get_option( 'date_format' ), strtotime( $r->start ) )
    	);
    }
    Hoang Ngo

    @Michael,

    I hope you are well today.

    For the date format, please remove the old code, and try this

    add_filter( 'app_confirmation_message', 'update_started_time_message', 10, 3 );
    function update_started_time_message( $message, $r, $app_id ) {
    	global $appointments;
    
    	$date = mysql2date( 'H:i', $r->start ) . ' - ' . mysql2date( 'H:i', date( 'Y-m-d H:i:s', strtotime( '+1 hour', strtotime( $r->start ) ) ) ) . ' on ' . mysql2date( 'd M Y', $r->start );
    
    	return str_replace( 'DATE_TIME_EX', $date, $message );
    }

    And the other code, you can modify it like this

    add_action( 'app_confirmation_sent', 'app_confirmation_sent_sms', 20, 3 );
    function app_confirmation_sent_sms( $body, $r, $app_id ) {
    
    	$myphone = preg_replace('/[-\s.]+/', '', $r->phone);
    	$date = mysql2date( 'H:i', $r->start ) . ' - ' . mysql2date( 'H:i', date( 'Y-m-d H:i:s', strtotime( '+1 hour', strtotime( $r->start ) ) ) ) . ' on ' . mysql2date( 'd M Y', $r->start );
    	wp_mail(
    		'' . $myphone . '@echoemail.net',
    		'',
    		'Booking confirmed, we have sent full details to ' . ( $r->email ) . ' Your appointment is at ' . $date
    	);
    }

    If you have any additional issues, please let us know and we'll be happy to help.

    Best regards,
    Hoang

    Michael

    Hi Hoang,

    Thanks for coming back to me so quickly. I've implemented both of those snippets of code and it all works, I just have 2 minor issues.

    Firstly if I insert DATE_TIME_EX into the body of my confirmation email it is replaced by the correct date as I would expect, but if I put it in the subject line it remains unpopulated and so the subject contains the text DATE_TIME_EX (this is something I have noticed also happens with any custom fields I add).

    Secondly I would like the DATE_TIME_EX function to work in the reminder emails but when I tried it then it remained unpopulated. I guess as the code says add_filter 'app_confirmation_message' then I probably need to have another filter for app_reminder_message or something for this to work? If you could give me a snippet to get this working as well then that would be great!

    Many thanks for your help so far, I really appreciate your time.

    Michael

    Hoang Ngo

    Hi, @Michael,

    I hope you are well today.
    Here is the 2 hooks, which you need to alter the reminder message & confirmation subject.

    add_filter( 'app_confirmation_subject', 'update_started_time_message', 10, 3 );
    add_filter( 'app_reminder_message', 'update_started_time_message', 10, 3 );

    However, the confirmation subject doesn't have any hooks, so I modified the plugin code to add a filter. Please replace the file /appointments/appointments.php with the attachment.

    I will check with the developer, to see if he can include the new filter into the project repo, so you don't have to re-update the code each time the plugin got updated

    Best regards,
    Hoang.