예제 #1
0
 function trav_tour_send_confirmation_email($booking_no, $booking_pincode, $type = 'new', $subject = '', $description = '')
 {
     global $wpdb, $logo_url, $trav_options;
     $booking_data = trav_tour_get_booking_data($booking_no, $booking_pincode);
     if (!empty($booking_data)) {
         // server variables
         $admin_email = get_option('admin_email');
         $home_url = esc_url(home_url());
         $site_name = $_SERVER['SERVER_NAME'];
         $logo_url = esc_url($logo_url);
         $tour_book_conf_url = '';
         if (isset($trav_options['tour_booking_confirmation_page']) && !empty($trav_options['tour_booking_confirmation_page'])) {
             $tour_book_conf_url = trav_get_permalink_clang($trav_options['tour_booking_confirmation_page']);
         }
         $booking_data['tour_id'] = trav_tour_clang_id($booking_data['tour_id']);
         $st_data = trav_tour_get_schedule_type_data($booking_data['tour_id'], $booking_data['st_id']);
         $schedule_data = trav_tour_get_schedule_data($booking_data);
         // tour info
         $tour_name = get_the_title($booking_data['tour_id']);
         $tour_url = esc_url(trav_get_permalink_clang($booking_data['tour_id']));
         $tour_thumbnail = get_the_post_thumbnail($booking_data['tour_id'], 'list-thumb');
         $tour_address = get_post_meta($booking_data['tour_id'], 'trav_tour_address', true);
         $tour_city = trav_tour_get_city($booking_data['tour_id']);
         $tour_country = trav_tour_get_country($booking_data['tour_id']);
         $tour_phone = get_post_meta($booking_data['tour_id'], 'trav_tour_phone', true);
         $tour_email = get_post_meta($booking_data['tour_id'], 'trav_tour_email', true);
         $tour_duration = '';
         if (!empty($schedule_data) && $schedule_data['success'] == 1) {
             $tour_duration = $schedule_data['schedule_data']['duration'];
         }
         $tour_st_title = esc_html(trav_tour_get_schedule_type_title($booking_data['tour_id'], $booking_data['st_id']));
         $tour_st_description = esc_html($st_data['description']);
         $tour_st_time = esc_html($st_data['time']);
         if (empty($tour_address)) {
             $tour_address = $tour_city . ' ' . $tour_country;
         }
         $tour_date = date('l, F, j, Y', trav_strtotime($booking_data['tour_date']));
         // booking info
         $booking_no = $booking_data['booking_no'];
         $booking_pincode = $booking_data['pin_code'];
         $booking_adults = $booking_data['adults'];
         $booking_kids = $booking_data['kids'];
         $booking_total_price = esc_html(trav_get_price_field($booking_data['total_price'] * $booking_data['exchange_rate'], $booking_data['currency_code'], 0));
         $booking_deposit_price = esc_html($booking_data['deposit_price'] . $booking_data['currency_code']);
         $booking_deposit_paid = esc_html(empty($booking_data['deposit_paid']) ? 'No' : 'Yes');
         $booking_update_url = esc_url(add_query_arg(array('booking_no' => $booking_data['booking_no'], 'pin_code' => $booking_data['pin_code']), $tour_book_conf_url));
         // customer info
         $customer_first_name = $booking_data['first_name'];
         $customer_last_name = $booking_data['last_name'];
         $customer_email = $booking_data['email'];
         $customer_country_code = $booking_data['country_code'];
         $customer_phone = $booking_data['phone'];
         $customer_address = $booking_data['address'];
         $customer_city = $booking_data['city'];
         $customer_zip = $booking_data['zip'];
         $customer_country = $booking_data['country'];
         $customer_special_requirements = $booking_data['special_requirements'];
         $variables = array('home_url', 'site_name', 'logo_url', 'tour_name', 'tour_url', 'tour_thumbnail', 'tour_country', 'tour_city', 'tour_address', 'tour_phone', 'tour_email', 'tour_date', 'tour_duration', 'tour_st_title', 'tour_st_description', 'tour_st_time', 'booking_no', 'booking_pincode', 'booking_adults', 'booking_kids', 'booking_total_price', 'booking_deposit_price', 'booking_deposit_paid', 'booking_update_url', 'customer_first_name', 'customer_last_name', 'customer_email', 'customer_country_code', 'customer_phone', 'customer_address', 'customer_city', 'customer_zip', 'customer_country', 'customer_special_requirements');
         if (empty($subject)) {
             if ($type == 'new') {
                 $subject = empty($trav_options['tour_confirm_email_subject']) ? 'Booking Confirmation Email Subject' : $trav_options['tour_confirm_email_subject'];
             } elseif ($type == 'update') {
                 $subject = empty($trav_options['tour_update_email_subject']) ? 'Booking Updated Email Subject' : $trav_options['tour_update_email_subject'];
             } elseif ($type == 'cancel') {
                 $subject = empty($trav_options['tour_cancel_email_subject']) ? 'Booking Canceled Email Subject' : $trav_options['tour_cancel_email_subject'];
             }
         }
         if (empty($description)) {
             if ($type == 'new') {
                 $description = empty($trav_options['tour_confirm_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['tour_confirm_email_description'];
             } elseif ($type == 'update') {
                 $description = empty($trav_options['tour_update_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['tour_update_email_description'];
             } elseif ($type == 'cancel') {
                 $description = empty($trav_options['tour_cancel_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['tour_cancel_email_description'];
             }
         }
         foreach ($variables as $variable) {
             $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
             $description = str_replace("[" . $variable . "]", ${$variable}, $description);
         }
         $mail_sent = trav_send_mail($site_name, $admin_email, $customer_email, $subject, $description);
         /* mailing function to business owner */
         $bowner_address = '';
         if (!empty($trav_options['tour_booked_notify_bowner'])) {
             if ($type == 'new') {
                 $subject = empty($trav_options['tour_bowner_email_subject']) ? 'You received a booking' : $trav_options['tour_bowner_email_subject'];
                 $description = empty($trav_options['tour_bowner_email_description']) ? 'Booking Details' : $trav_options['tour_bowner_email_description'];
             } elseif ($type == 'update') {
                 $subject = empty($trav_options['tour_update_bowner_email_subject']) ? 'A booking is updated' : $trav_options['tour_update_bowner_email_subject'];
                 $description = empty($trav_options['tour_update_bowner_email_description']) ? 'Booking Details' : $trav_options['tour_update_bowner_email_description'];
             } elseif ($type == 'cancel') {
                 $subject = empty($trav_options['tour_cancel_bowner_email_subject']) ? 'A booking is canceled' : $trav_options['tour_cancel_bowner_email_subject'];
                 $description = empty($trav_options['tour_cancel_bowner_email_description']) ? 'Booking Details' : $trav_options['tour_cancel_bowner_email_description'];
             }
             foreach ($variables as $variable) {
                 $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
                 $description = str_replace("[" . $variable . "]", ${$variable}, $description);
             }
             if (!empty($tour_email)) {
                 $bowner_address = $tour_email;
             } else {
                 $post_author_id = get_post_field('post_author', $booking_data['tour_id']);
                 $bowner = get_user_by('id', $post_author_id);
                 if (!empty($bowner)) {
                     $bowner_address = $bowner->user_email;
                 }
             }
             if (!empty($bowner_address)) {
                 trav_send_mail($site_name, $admin_email, $bowner_address, $subject, $description);
             }
         }
         /* mailing function to admin */
         if (!empty($trav_options['tour_booked_notify_admin'])) {
             if ($bowner_address != $admin_email) {
                 if ($type == 'new') {
                     $subject = empty($trav_options['tour_admin_email_subject']) ? 'You received a booking' : $trav_options['tour_admin_email_subject'];
                     $description = empty($trav_options['tour_admin_email_description']) ? 'Booking Details' : $trav_options['tour_admin_email_description'];
                 } elseif ($type == 'update') {
                     $subject = empty($trav_options['tour_update_admin_email_subject']) ? 'A booking is updated' : $trav_options['tour_update_admin_email_subject'];
                     $description = empty($trav_options['tour_update_admin_email_description']) ? 'Booking Details' : $trav_options['tour_update_admin_email_description'];
                 } elseif ($type == 'cancel') {
                     $subject = empty($trav_options['tour_cancel_admin_email_subject']) ? 'A booking is canceled' : $trav_options['tour_cancel_admin_email_subject'];
                     $description = empty($trav_options['tour_cancel_admin_email_description']) ? 'Booking Details' : $trav_options['tour_cancel_admin_email_description'];
                 }
                 foreach ($variables as $variable) {
                     $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
                     $description = str_replace("[" . $variable . "]", ${$variable}, $description);
                 }
                 trav_send_mail($site_name, $admin_email, $admin_email, $subject, $description);
             }
         }
         return true;
     }
     return false;
 }
예제 #2
0
 function trav_acc_send_confirmation_email($booking_no, $booking_pincode, $type = 'new', $subject = '', $description = '')
 {
     global $wpdb, $logo_url, $trav_options;
     $booking_data = trav_acc_get_booking_data($booking_no, $booking_pincode);
     if (!empty($booking_data)) {
         // server variables
         $admin_email = get_option('admin_email');
         $home_url = esc_url(home_url());
         $site_name = $_SERVER['SERVER_NAME'];
         $logo_url = esc_url($logo_url);
         $acc_book_conf_url = trav_acc_get_book_conf_url();
         $booking_data['accommodation_id'] = trav_acc_clang_id($booking_data['accommodation_id']);
         $booking_data['room_type_id'] = trav_room_clang_id($booking_data['room_type_id']);
         // accommodation info
         $accommodation_name = get_the_title($booking_data['accommodation_id']);
         $accommodation_url = esc_url(trav_get_permalink_clang($booking_data['accommodation_id']));
         $accommodation_thumbnail = get_the_post_thumbnail($booking_data['accommodation_id'], 'list-thumb');
         $accommodation_address = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_address', true);
         $accommodation_city = trav_acc_get_city($booking_data['accommodation_id']);
         $accommodation_country = trav_acc_get_country($booking_data['accommodation_id']);
         $accommodation_phone = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_phone', true);
         $accommodation_email = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_email', true);
         $accommodation_room_name = esc_html(get_the_title($booking_data['room_type_id']));
         if (empty($accommodation_address)) {
             $accommodation_address = $accommodation_city . ' ' . $accommodation_country;
         }
         $check_in = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_check_in', true);
         $check_out = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_check_out', true);
         $check_in_time = empty($check_in) ? $booking_data['date_from'] : $booking_data['date_from'] . ' ' . $check_in;
         $check_out_time = empty($check_out) ? $booking_data['date_to'] : $booking_data['date_to'] . ' ' . $check_out;
         // booking info
         $booking_no = $booking_data['booking_no'];
         $booking_pincode = $booking_data['pin_code'];
         $date_from = new DateTime($booking_data['date_from']);
         $date_to = new DateTime($booking_data['date_to']);
         $number1 = $date_from->format('U');
         $number2 = $date_to->format('U');
         $booking_nights = ($number2 - $number1) / (3600 * 24);
         $booking_checkin_time = date('l, F, j, Y', trav_strtotime($booking_data['date_from']));
         $booking_checkout_time = date('l, F, j, Y', trav_strtotime($booking_data['date_to']));
         $booking_rooms = $booking_data['rooms'];
         $booking_adults = $booking_data['adults'];
         $booking_kids = $booking_data['kids'];
         $booking_room_price = esc_html(trav_get_price_field($booking_data['room_price'] * $booking_data['exchange_rate'], $booking_data['currency_code'], 0));
         $booking_tax = esc_html(trav_get_price_field($booking_data['tax'] * $booking_data['exchange_rate'], $booking_data['currency_code'], 0));
         $booking_total_price = esc_html(trav_get_price_field($booking_data['total_price'] * $booking_data['exchange_rate'], $booking_data['currency_code'], 0));
         $booking_deposit_price = esc_html($booking_data['deposit_price'] . $booking_data['currency_code']);
         $booking_deposit_paid = esc_html(empty($booking_data['deposit_paid']) ? 'No' : 'Yes');
         $booking_update_url = esc_url(add_query_arg(array('booking_no' => $booking_data['booking_no'], 'pin_code' => $booking_data['pin_code']), $acc_book_conf_url));
         // customer info
         $customer_first_name = $booking_data['first_name'];
         $customer_last_name = $booking_data['last_name'];
         $customer_email = $booking_data['email'];
         $customer_country_code = $booking_data['country_code'];
         $customer_phone = $booking_data['phone'];
         $customer_address = $booking_data['address'];
         $customer_city = $booking_data['city'];
         $customer_zip = $booking_data['zip'];
         $customer_country = $booking_data['country'];
         $customer_special_requirements = $booking_data['special_requirements'];
         $variables = array('home_url', 'site_name', 'logo_url', 'accommodation_name', 'accommodation_url', 'accommodation_thumbnail', 'accommodation_country', 'accommodation_city', 'accommodation_address', 'accommodation_phone', 'accommodation_email', 'accommodation_room_name', 'booking_no', 'booking_pincode', 'booking_nights', 'booking_checkin_time', 'booking_checkout_time', 'booking_rooms', 'booking_adults', 'booking_kids', 'booking_room_price', 'booking_tax', 'booking_total_price', 'booking_deposit_price', 'booking_deposit_paid', 'booking_update_url', 'customer_first_name', 'customer_last_name', 'customer_email', 'customer_country_code', 'customer_phone', 'customer_address', 'customer_city', 'customer_zip', 'customer_country', 'customer_special_requirements');
         if (empty($subject)) {
             if ($type == 'new') {
                 $subject = empty($trav_options['acc_confirm_email_subject']) ? 'Booking Confirmation Email Subject' : $trav_options['acc_confirm_email_subject'];
             } elseif ($type == 'update') {
                 $subject = empty($trav_options['acc_update_email_subject']) ? 'Booking Updated Email Subject' : $trav_options['acc_update_email_subject'];
             } elseif ($type == 'cancel') {
                 $subject = empty($trav_options['acc_cancel_email_subject']) ? 'Booking Canceled Email Subject' : $trav_options['acc_cancel_email_subject'];
             }
         }
         if (empty($description)) {
             if ($type == 'new') {
                 $description = empty($trav_options['acc_confirm_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['acc_confirm_email_description'];
             } elseif ($type == 'update') {
                 $description = empty($trav_options['acc_update_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['acc_update_email_description'];
             } elseif ($type == 'cancel') {
                 $description = empty($trav_options['acc_cancel_email_description']) ? 'Booking Confirmation Email Description' : $trav_options['acc_cancel_email_description'];
             }
         }
         foreach ($variables as $variable) {
             $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
             $description = str_replace("[" . $variable . "]", ${$variable}, $description);
         }
         if (!empty($trav_options['acc_confirm_email_ical']) && $type == 'new') {
             $mail_sent = trav_send_ical_event($site_name, $admin_email, $customer_first_name . ' ' . $customer_last_name, $customer_email, $check_in_time, $check_out_time, $subject, $description, $accommodation_address);
         } else {
             $mail_sent = trav_send_mail($site_name, $admin_email, $customer_email, $subject, $description);
         }
         /* mailing function to business owner */
         $bowner_address = '';
         if (!empty($trav_options['acc_booked_notify_bowner'])) {
             if ($type == 'new') {
                 $subject = empty($trav_options['acc_bowner_email_subject']) ? 'You received a booking' : $trav_options['acc_bowner_email_subject'];
                 $description = empty($trav_options['acc_bowner_email_description']) ? 'Booking Details' : $trav_options['acc_bowner_email_description'];
             } elseif ($type == 'update') {
                 $subject = empty($trav_options['acc_update_bowner_email_subject']) ? 'A booking is updated' : $trav_options['acc_update_bowner_email_subject'];
                 $description = empty($trav_options['acc_update_bowner_email_description']) ? 'Booking Details' : $trav_options['acc_update_bowner_email_description'];
             } elseif ($type == 'cancel') {
                 $subject = empty($trav_options['acc_cancel_bowner_email_subject']) ? 'A booking is canceled' : $trav_options['acc_cancel_bowner_email_subject'];
                 $description = empty($trav_options['acc_cancel_bowner_email_description']) ? 'Booking Details' : $trav_options['acc_cancel_bowner_email_description'];
             }
             foreach ($variables as $variable) {
                 $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
                 $description = str_replace("[" . $variable . "]", ${$variable}, $description);
             }
             if (!empty($accommodation_email)) {
                 $bowner_address = $accommodation_email;
             } else {
                 $post_author_id = get_post_field('post_author', $booking_data['accommodation_id']);
                 $bowner = get_user_by('id', $post_author_id);
                 if (!empty($bowner)) {
                     $bowner_address = $bowner->user_email;
                 }
             }
             if (!empty($bowner_address)) {
                 trav_send_mail($site_name, $admin_email, $bowner_address, $subject, $description);
             }
         }
         /* mailing function to admin */
         if (!empty($trav_options['acc_booked_notify_admin'])) {
             if ($bowner_address != $admin_email) {
                 if ($type == 'new') {
                     $subject = empty($trav_options['acc_admin_email_subject']) ? 'You received a booking' : $trav_options['acc_admin_email_subject'];
                     $description = empty($trav_options['acc_admin_email_description']) ? 'Booking Details' : $trav_options['acc_admin_email_description'];
                 } elseif ($type == 'update') {
                     $subject = empty($trav_options['acc_update_admin_email_subject']) ? 'A booking is updated' : $trav_options['acc_update_admin_email_subject'];
                     $description = empty($trav_options['acc_update_admin_email_description']) ? 'Booking Details' : $trav_options['acc_update_admin_email_description'];
                 } elseif ($type == 'cancel') {
                     $subject = empty($trav_options['acc_cancel_admin_email_subject']) ? 'A booking is canceled' : $trav_options['acc_cancel_admin_email_subject'];
                     $description = empty($trav_options['acc_cancel_admin_email_description']) ? 'Booking Details' : $trav_options['acc_cancel_admin_email_description'];
                 }
                 foreach ($variables as $variable) {
                     $subject = str_replace("[" . $variable . "]", ${$variable}, $subject);
                     $description = str_replace("[" . $variable . "]", ${$variable}, $description);
                 }
                 trav_send_mail($site_name, $admin_email, $admin_email, $subject, $description);
             }
         }
         return true;
     }
     return false;
 }