Send removal email on client cancellation

Hi
We have an email set up when an Administrator cancels an appointment for the Client. This works well. Can you please tell me how to send the same email when a client cancels their appointment on the front end?

Thanks
Vandana

  • aristath

    Hello there @vandana, i hope you're well today!

    As mentioned in your other thread on https://premium.wpmudev.org/forums/topic/appointments-cancellation-email when a user cancels their appointment they don't need an email telling them that they did something that they wanted to do...

    Emails are required when you want to notify the user of something. Like for example when an administrator cancels their appointment, in which case they have to be notified about it.

    Currently there is no implementation to send emails to users to confirm that the appointment they just canceled has been canceled there was never a need to do that!

    However, I just submitted this as a feature request as I can see how that would be useful in some use cases. :slight_smile:

    Cheers,
    Ari.

  • vandana

    Hi Ari

    Good catch and explanation.

    What I really meant to request was that the administrator resource an email when the client cancels on the front end.

    Thought now from an operations perspective the problem is that once an appointment is made we have a bunch of verification steps. If the client camels the verification steps are no longer needed but we are having a hard time keeping track of the cancelations and sometimes verification is done for canceled appointments when it is not needed. It ends up choosing us time and money.

    Thanks for your help
    Vandana

  • Ash

    Hello @Vandana

    I hope you are well today.

    Sending to client is not possible as Ari said. If you want to send email to admin when someone cancels an appointment, you can try following code:

    add_action( 'app-appointments-appointment_cancelled', 'send_email_admin' );
    function send_email_admin( $app_id ){
        global $appointments;
        wp_mail( $appointments->get_admin_email(), 'Appointment cancelled', 'An appointment is cancelled by the user, which id is '. $app_id );
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • vandana

    Hi Ash
    I found the code you provided in other forum topics already. Just sending the ID of the appointment is not sufficient per the requirements. The email needs to include the Appointment Date/Time, Client Name and Provider Name in the email. Can you please tell me how to ensure all that information is included in the email?

    At that point, this will be fully functional option.

    Thanks
    Vandana

  • Ash

    Hello @Vardana

    I hope you are well today.

    Please try the following code:

    add_action( 'app-appointments-appointment_cancelled', 'send_email_admin' );
    function send_email_admin( $app_id ){
        global $appointments;
        global $wpdb;
    
        $sql = "SELECT * from " . $wpdb->prefix . "app_appointments where ID = '".$app_id."'";
        $app = $wpdb->get_row( $sql, OBJECT );
    
        $date_time = mysql2date($appointments->datetime_format, $app->start);
        $client_name = $appointments->get_client_name( $app_id );
        $provider_name = $appointments->get_worker_name( $app->worker );
    
        wp_mail(
    	    $appointments->get_admin_email(),
    	    'Appointment cancelled',
    	    'An appointment is cancelled by the user.<br><br>
    	    Name: '.$client_name.'<br>
    	    Date/Time: '.$date_time.'<br>
    	    Provider Name: '.$provider_name
    	    );
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • vandana

    Hi Ash

    Thanks for the support. It worked perfectly. I made a small modification to ensure the email is formatted properly on the client side. Please feel free to use it for your next support request.

    add_action( 'app-appointments-appointment_cancelled', 'send_email_admin' );
    function send_email_admin( $app_id ){
        global $appointments;
        global $wpdb;
    
        $sql = "SELECT * from " . $wpdb->prefix . "app_appointments where ID = '".$app_id."'";
        $app = $wpdb->get_row( $sql, OBJECT );
    
        $date_time = mysql2date($appointments->datetime_format, $app->start);
        $client_name = $appointments->get_client_name( $app_id );
        $provider_name = $appointments->get_worker_name( $app->worker );
        $headers = array('Content-Type: text/html; charset=UTF-8');
    
        wp_mail(
    	    $appointments->get_admin_email(),
    	    'An Appointment was cancelled',
    	    'Dear Admin: <br />
    	    The following appointment was cancelled by the user. <br /><br />
    	    Name: '.$client_name.'<br />
    	    Date/Time: '.$date_time.'<br />
    	    Location: '.$provider_name,
    	    $headers
    	    );
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.