Custom Fields in Service Providers Emails with Appointments+

I'm using some custom additional fields, and I want those to appear in the email to service providers. I copied some code from one of the previous users but it isn't working.

Here is my code below, in this example I have a couple of custom fields (FIELD_COMPANY for example). How can I reference those in the email that is sent out?

// APPOINTMENTS MESSAGE

function custom_app_messages_worker_notification( $body, $r, $app_id ){

	global $appointments;

	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

	$client_email = $r->email;
	$client_phone = $r->phone;
	$client_name = $r->name;
	$service_name = $appointments->get_service_name( $r->service);
	$worker_name = $appointments->get_worker_name( $r->worker);
	$date_time = date_i18n( 'Y-m-d H:i:s', strtotime($r->start));

	$body = "Hi $worker_name,

	An appointment requires your confirmation.

	Here are the appointment details:
	Requested service: $service_name
	Date and time: $date_time
	Client email: $client_email
	Client Name: $client_name
	Client Phone Number: $client_phone

	Company: $FIELD_COMPANY
	Role with company: $FIELD_ROLEWITHCOMPANY
	Country: $FIELD_COUNTRY
	Amount of Storage: $FIELD_AMOUNTOFSTORAGE
	Purchase Decision Timeframe: $FIELD_PURCHASEDECISIONTIMEFRAME
	Industry: $FIELD_INDUSTRY
	Time Zone: $FIELD_INDUSTRY

	Best regards,
	$blogname
	";

	return $body;

}
add_filter('app-messages-worker-notification', 'custom_app_messages_worker_notification', 10, 3);

That's from my functions.php file.

  • Vinod Dalvi

    Hi Chris,

    Welcome to the WPMU Dev community and thank you for your question.

    I have tested on my test site using latest version of Appointments+ plugin and using your shared code as a plugin which i have attached to this reply.

    The shared custom code worked fine for me without any issue.

    Please keep in mind that this appointment confirmation required email only gets sent to the service provider when the appointment confirmation is required that means when the "Auto confirm" option is set to No in the Appointments+ Accessibility Settings and when you have configured the Appointments+ plugin Notification Settings to send the emails.

    You will get your custom field values from the argument $r passed to the custom filter function custom_app_messages_worker_notification as displayed in your shared code.

    Best Regards,
    Vinod Dalvi

  • Ash

    Hi there

    Would you please try the following code?

    function custom_app_messages_worker_notification( $body, $r, $app_id ){
    
    	global $appointments;
    
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    
    	$client_email = $r->email;
    	$client_phone = $r->phone;
    	$client_name = $r->name;
    	$service_name = $appointments->get_service_name( $r->service);
    	$worker_name = $appointments->get_worker_name( $r->worker);
    	$date_time = date_i18n( 'Y-m-d H:i:s', strtotime($r->start));
    
    	$body = "Hi $worker_name,
    
    	An appointment requires your confirmation.
    
    	Here are the appointment details:
    	Requested service: $service_name
    	Date and time: $date_time
    	Client email: $client_email
    	Client Name: $client_name
    	Client Phone Number: $client_phone
    
    	Company: FIELD_COMPANY
    	Role with company: FIELD_ROLEWITHCOMPANY
    	Country: FIELD_COUNTRY
    	Amount of Storage: FIELD_AMOUNTOFSTORAGE
    	Purchase Decision Timeframe: FIELD_PURCHASEDECISIONTIMEFRAME
    	Industry: FIELD_INDUSTRY
    	Time Zone: FIELD_INDUSTRY
    
    	Best regards,
    	$blogname
    	";
    
    	return apply_filters( 'app_notification_message', $body, $r, $app_id );
    
    }
    add_filter('app-messages-worker-notification', 'custom_app_messages_worker_notification', 10, 3);

    Please let us know if that works.

    Cheers
    Ash

  • Chris

    Hi! That totally worked!

    I guess my only remaining question is how would I go about showing the notes field? I tried $notes but that didn't work. Figured I'd just ask since you would probably know if that's easy to show. Thanks.

    Here is what I have, which is the same as your just added a $notes field which didn't work.

    function custom_app_messages_worker_notification( $body, $r, $app_id ){
    
    	global $appointments;
    
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    
    	$client_email = $r->email;
    	$client_phone = $r->phone;
    	$client_name = $r->name;
    	$service_name = $appointments->get_service_name( $r->service);
    	$worker_name = $appointments->get_worker_name( $r->worker);
    	$date_time = date_i18n( 'Y-m-d H:i:s', strtotime($r->start));
    
    	$body = "Hi $worker_name,
    
    	An appointment requires your confirmation.
    
    	Here are the appointment details:
    	Requested service: $service_name
    	Date and time: $date_time
    	Client email: $client_email
    	Client Name: $client_name
    	Client Phone Number: $client_phone
    
    	Company: FIELD_COMPANY
    	Role with company: FIELD_ROLEWITHCOMPANY
    	Country: FIELD_COUNTRY
    	Amount of Storage: FIELD_AMOUNTOFSTORAGE
    	Purchase Decision Timeframe: FIELD_PURCHASEDECISIONTIMEFRAME
    	Industry: FIELD_INDUSTRY
    	Time Zone: FIELD_INDUSTRY
    
    	Notes: $notes
    
    	Best regards,
    	$blogname
    	";
    
    	return apply_filters( 'app_notification_message', $body, $r, $app_id );
    
    }
    add_filter('app-messages-worker-notification', 'custom_app_messages_worker_notification', 10, 3);
  • Ash

    Hi there

    You can use $r->note to send note. Like the following:

    <?php
    
    function custom_app_messages_worker_notification( $body, $r, $app_id ){
    
    	global $appointments;
    
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    
    	$client_email = $r->email;
    	$client_phone = $r->phone;
    	$client_name = $r->name;
    	$service_name = $appointments->get_service_name( $r->service);
    	$worker_name = $appointments->get_worker_name( $r->worker);
    	$date_time = date_i18n( 'Y-m-d H:i:s', strtotime($r->start));
    
    	$body = "Hi $worker_name,
    
    	An appointment requires your confirmation.
    
    	Here are the appointment details:
    	Requested service: $service_name
    	Date and time: $date_time
    	Client email: $client_email
    	Client Name: $client_name
    	Client Phone Number: $client_phone
    
    	Company: FIELD_COMPANY
    	Role with company: FIELD_ROLEWITHCOMPANY
    	Country: FIELD_COUNTRY
    	Amount of Storage: FIELD_AMOUNTOFSTORAGE
    	Purchase Decision Timeframe: FIELD_PURCHASEDECISIONTIMEFRAME
    	Industry: FIELD_INDUSTRY
    	Time Zone: FIELD_INDUSTRY
    
    	Notes: {$r->note}
    
    	Best regards,
    	$blogname
    	";
    
    	return apply_filters( 'app_notification_message', $body, $r, $app_id );
    
    }
    add_filter('app-messages-worker-notification', 'custom_app_messages_worker_notification', 10, 3);

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

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.