/** * add_pdf_invoice_email_attachment. */ function add_pdf_invoice_email_attachment($attachments, $status, $order) { $invoice_types_ids = wcj_get_enabled_invoice_types_ids(); foreach ($invoice_types_ids as $invoice_type_id) { if (false === $this->do_attach_for_payment_method($invoice_type_id, $order->payment_method)) { continue; } $send_on_statuses = get_option('wcj_invoicing_' . $invoice_type_id . '_attach_to_emails', array()); if ('' == $send_on_statuses) { $send_on_statuses = array(); } if (in_array($status, $send_on_statuses)) { $the_invoice = wcj_get_pdf_invoice($order->id, $invoice_type_id); $file_name = $the_invoice->get_pdf('F'); if ('' != $file_name) { $attachments[] = $file_name; } } } return $attachments; }
/** * do_attach_for_payment_method. * function do_attach_for_payment_method( $payment_method ) { return ( 'no' === get_option( 'wcj_gateways_attach_invoice_' . $payment_method, 'yes' ) ) ? false : true; } /** * add_pdf_invoice_email_attachment. */ function add_pdf_invoice_email_attachment($attachments, $status, $order) { $invoice_types_ids = wcj_get_enabled_invoice_types_ids(); foreach ($invoice_types_ids as $invoice_type_id) { //if ( 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( 'wcj_invoicing_' . $invoice_type_id . '_attach_to_email_enabled' ) ) ) { //if ( isset( $status ) && 'customer_completed_order' === $status && isset( $order ) && true === $this->do_attach_for_payment_method( $order->payment_method ) ) { //if ( 'customer_completed_order' === $status ) { $send_on_statuses = get_option('wcj_invoicing_' . $invoice_type_id . '_attach_to_emails', array()); if ('' == $send_on_statuses) { $send_on_statuses = array(); } if (in_array($status, $send_on_statuses)) { $the_invoice = wcj_get_pdf_invoice($order->id, $invoice_type_id); $file_name = $the_invoice->get_pdf('F'); if ('' != $file_name) { $attachments[] = $file_name; } } } return $attachments; }
} /** * generate_pdf_on_init. */ function generate_pdf_on_init() { // Check if all is OK if (true !== $this->get_invoice || 0 == $this->order_id || !is_user_logged_in() || !current_user_can('administrator') && !is_shop_manager() && get_current_user_id() != intval(get_post_meta($this->order_id, '_customer_user', true))) { return; } $the_invoice = wcj_get_pdf_invoice($this->order_id, $this->invoice_type_id); // $invoice = new WCJ_PDF_Invoice(); $dest = true === $this->save_as_pdf ? 'D' : 'I'; // $invoice->get_pdf( $this->order_id, $this->invoice_type_id, '', $dest );//, $this->invoice_type_id ); $the_invoice->get_pdf($dest); // echo $invoice_html;
/** * get_invoices_report_zip. * * @version 2.3.10 * @since 2.3.10 */ function get_invoices_report_zip($year, $month, $invoice_type_id) { $zip = new ZipArchive(); $zip_file_name = $year . '_' . $month . '-' . $invoice_type_id . '.zip'; $zip_file_path = sys_get_temp_dir() . '/' . $zip_file_name; if (file_exists($zip_file_path)) { unlink($zip_file_path); } if ($zip->open($zip_file_path, ZipArchive::CREATE) !== TRUE) { return false; } $offset = 0; $block_size = 96; while (true) { $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'ASC', 'year' => $year, 'monthnum' => $month, 'offset' => $offset); $loop = new WP_Query($args); if (!$loop->have_posts()) { break; } while ($loop->have_posts()) { $loop->the_post(); $order_id = $loop->post->ID; if (wcj_is_invoice_created($order_id, $invoice_type_id)) { $the_invoice = wcj_get_pdf_invoice($order_id, $invoice_type_id); $file_name = $the_invoice->get_pdf('F'); $zip->addFile($file_name, $the_invoice->get_file_name()); } } $offset += $block_size; } /* $output .= "numfiles: " . $zip->numFiles . "\n"; $output .= "status: " . $zip->getStatusString() . "\n"; */ $zip->close(); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=" . urlencode($zip_file_name)); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); header("Content-Length: " . filesize($zip_file_path)); flush(); // this doesn't really matter. if (false !== ($fp = fopen($zip_file_path, "r"))) { while (!feof($fp)) { echo fread($fp, 65536); flush(); // this is essential for large downloads } fclose($fp); } else { die(__('Unexpected error', 'woocommerce-jetpack')); } return true; }