global $wp; if (isset($wp->query_vars['view-bill'])) { $invoice_id = absint($wp->query_vars['view-bill']); if (!empty($invoice_id)) { $invoice = wc_gzdp_get_invoice($invoice_id); $order_id = $invoice->order; if (!current_user_can('manage_woocommerce') && !current_user_can('view_order', $order_id)) { wp_die(__('Cheatin huh?', 'woocommerce-germanized-pro')); } self::download($invoice); } } } public static function download($invoice, $force = false) { if (!$invoice->has_attachment() || !file_exists($invoice->get_pdf_path())) { wp_die(__('This file does not exist', 'woocommerce-germanized-pro')); } $file = $invoice->get_pdf_path(); $filename = $invoice->get_filename(); header('Content-type: application/pdf'); header('Content-Disposition: ' . (get_option('woocommerce_gzdp_invoice_download_force') == 'yes' || $force ? 'attachment' : 'inline') . '; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Accept-Ranges: bytes'); @readfile($file); exit; } } WC_GZDP_Download_Handler::init();