/**
  * Attaches invoice to a specific WooCommerce email. Invoice will only be generated when it does not exists already.
  * @param $attachments
  * @param $status
  * @param $order
  * @return array
  */
 function attach_invoice_to_email($attachments, $status, $order)
 {
     $general_options = get_option('bewpi_general_settings');
     if ($status == $general_options['bewpi_email_type'] || $general_options['bewpi_new_order'] && $status == "new_order") {
         $invoice = new BEWPI_Invoice($order->id);
         if (!$invoice->exists()) {
             $filename = $invoice->save("F");
         } else {
             $filename = $invoice->get_filename();
         }
         $attachments[] = $filename;
     }
     return $attachments;
 }
 /**
  * Attaches invoice to a specific WooCommerce email. Invoice will only be generated when it does not exists already.
  *
  * @param $attachments
  * @param $status
  * @param $order
  *
  * @return array
  */
 function attach_invoice_to_email($attachments, $status, $order)
 {
     $general_options = get_option('bewpi_general_settings');
     if ($status == $general_options['bewpi_email_type'] || $general_options['bewpi_new_order'] && $status == "new_order") {
         $invoice = new BEWPI_Invoice($order->id);
         // create new invoice if doesn't exists, else get the full path from it..
         $full_path = !$invoice->exists() ? $invoice->save("F") : $invoice->get_full_path();
         $attachments[] = $full_path;
     }
     return $attachments;
 }
 /**
  * Attaches invoice to a specific WooCommerce email. Invoice will only be generated when it does not exists already.
  *
  * @param $attachments
  * @param $status
  * @param $order
  *
  * @return array
  */
 function attach_invoice_to_email($attachments, $status, $order)
 {
     $attachments = apply_filters('bewpi_email_attachments', $attachments, $status, $order);
     $general_options = get_option('bewpi_general_settings');
     if (empty($general_options["bewpi_email_type"]) || $status !== $general_options["bewpi_email_type"]) {
         return $attachments;
     }
     $payment_methods = apply_filters('bewpi_attach_invoice_excluded_payment_methods', array());
     if (in_array($order->payment_method, $payment_methods)) {
         return $attachments;
     }
     $invoice = new BEWPI_Invoice($order->id);
     if ($invoice->exists()) {
         $full_path = $invoice->get_full_path();
     } else {
         $full_path = $invoice->save("F");
     }
     // only add to attachments if it isn't already added.
     if (!in_array($full_path, $attachments)) {
         $attachments[] = $full_path;
     }
     return $attachments;
 }