Skip to content

Instantly share code, notes, and snippets.

@digamber89
Created August 6, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digamber89/2ec6c321fe7de86be33bacff0afefe82 to your computer and use it in GitHub Desktop.
Save digamber89/2ec6c321fe7de86be33bacff0afefe82 to your computer and use it in GitHub Desktop.
Send Order E-mails to Zoom Hosts when Booking is Made
<?php
//this code is expected to be added in child theme or custom functions.php
add_action( 'woocommerce_order_status_cancelled_to_processing_notification', 'send_email_to_booking_host', 10, 2 );
add_action( 'woocommerce_order_status_failed_to_processing_notification', 'send_email_to_booking_host', 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_processing_notification', 'send_email_to_booking_host', 10, 2 );
add_action( 'woocommerce_order_status_pending_to_processing_notification', 'send_email_to_booking_host', 10, 2 );
add_action( 'woocommerce_order_status_completed_notification', 'send_email_to_booking_host', 10, 2 );
/**
* @param $order_id
* @param \WC_Order $order
*/
function send_email_to_booking_host( $order_id, $order ) {
$booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_id( $order_id );
if ( empty( $booking_ids ) ) {
return;
}
foreach ( $booking_ids as $booking_id ) {
$meeting_details = json_decode( get_post_meta( $booking_id, '_vczapi_woo_addon_meeting_details', true ) );
if ( is_object( $meeting_details ) ) {
$meeting_topic = $meeting_details->topic;
$meeting_start_url = $meeting_details->start_url;
$timezone = $meeting_details->timezone;
$meeting_host_id = $meeting_details->host_id;
$meeting_start_time = $meeting_details->start_time;
$host_details = zoom_conference()->getUserInfo( $meeting_host_id );
$host_details = json_decode( $host_details );
$meeting_time = vczapi_dateConverter( $meeting_start_time, $timezone, 'Y-m-d H:i a' );
if ( is_object( $host_details ) ) {
if ( isset( $host_details->email ) && ! empty( $host_details->email ) ) {
$fist_name = $host_details->first_name;
$last_name = $host_details->last_name;
$name = $fist_name . $last_name;
$name = ! empty( $name ) ? $name : $host_details->email;
}
$blog_info = get_bloginfo( 'name' );
$site_url = get_site_url();
$message = "Hi " . $name . " this e-mail is sent from (" . $blog_info . ")<" . $site_url . "> notifying you that a user has purchased a Zoom Meeting, the details for the meeting are as follows: \r\n\r\n Meeting Topic: " . $meeting_topic . "\r\n\r\n Meeting Date and Time: " . $meeting_time . "\r\n\r\n Meeting Timezone: " . $timezone . "\r\n\r\n Start Meeting URL: <" . $meeting_start_url . ">";
wp_mail( $host_details->email, 'Zoom Meeting : ' . $meeting_topic, $message );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment