public function output()
 {
     $attachments = array();
     if ($this->query->have_posts()) {
         while ($this->query->have_posts()) {
             $this->query->the_post();
             global $post;
             $invoice = WC_Germanized_Pro()->invoice_factory->get_invoice($post);
             if ($invoice->has_attachment()) {
                 $attachments[$invoice->id] = array('path' => $invoice->get_pdf_path(), 'filename' => $invoice->get_filename());
             }
         }
     }
     if (!empty($attachments)) {
         $upload_dir = WC_germanized_pro()->get_upload_dir();
         $this->filename = wp_unique_filename($upload_dir['path'], $this->filename);
         $this->filepath = trailingslashit($upload_dir['path']) . $this->filename;
         $zip = new ZipArchive();
         $zip->open($this->filepath, ZipArchive::CREATE);
         foreach ($attachments as $attachment) {
             $zip->addFile($attachment['path'], $attachment['filename']);
         }
         $zip->close();
         header('Content-Length: ' . filesize($this->filepath));
         readfile($this->filepath);
     }
 }
コード例 #2
0
 public function output()
 {
     do_action('wc_gzdp_before_invoice_export_output');
     $data = array();
     if ($this->query->have_posts()) {
         while ($this->query->have_posts()) {
             $this->query->the_post();
             global $post;
             $invoice = WC_Germanized_Pro()->invoice_factory->get_invoice($post);
             $data[$invoice->id] = $this->get_export_data($invoice);
         }
     }
     $write = $this->prepare($data);
     $df = fopen("php://output", 'w');
     fputcsv($df, array_keys(reset($data)));
     foreach ($write as $row) {
         fwrite($df, $row);
     }
     fclose($df);
 }