/**
  * Attach the .ics files in the emails.
  *
  * @param  array  $attachments
  * @param  string $email_id
  * @param  mixed  $booking
  *
  * @return array
  */
 public function attach_ics_file($attachments, $email_id, $booking)
 {
     $available = apply_filters('woocommerce_bookings_emails_ics', array('booking_confirmed', 'booking_reminder'));
     if (in_array($email_id, $available)) {
         $generate = new WC_Bookings_ICS_Exporter();
         $attachments[] = $generate->get_booking_ics($booking);
     }
     return $attachments;
 }
 /**
  * Provides an email notification form
  */
 public function notifications_page()
 {
     global $woocommerce;
     if (!empty($_POST) && check_admin_referer('send_booking_notification')) {
         $notification_product_id = absint($_POST['notification_product_id']);
         $notification_subject = wc_clean(stripslashes($_POST['notification_subject']));
         $notification_message = wp_kses_post(stripslashes($_POST['notification_message']));
         try {
             if (!$notification_product_id) {
                 throw new Exception(__('Please choose a product', 'woocommerce-bookings'));
             }
             if (!$notification_message) {
                 throw new Exception(__('Please enter a message', 'woocommerce-bookings'));
             }
             if (!$notification_subject) {
                 throw new Exception(__('Please enter a subject', 'woocommerce-bookings'));
             }
             $bookings = WC_Bookings_Controller::get_bookings_for_product($notification_product_id);
             $mailer = $woocommerce->mailer();
             $notification = $mailer->emails['WC_Email_Booking_Notification'];
             $attachments = array();
             foreach ($bookings as $booking) {
                 // Add .ics file
                 if (isset($_POST['notification_ics'])) {
                     $generate = new WC_Bookings_ICS_Exporter();
                     $attachments[] = $generate->get_booking_ics($booking);
                 }
                 $notification->trigger($booking->id, $notification_subject, $notification_message, $attachments);
             }
             echo '<div class="updated fade"><p>' . __('Notification sent successfully', 'woocommerce-bookings') . '</p></div>';
         } catch (Exception $e) {
             echo '<div class="error"><p>' . $e->getMessage() . '</p></div>';
         }
     }
     $booking_products = WC_Bookings_Admin::get_booking_products();
     include 'views/html-notifications-page.php';
 }