public function download_invoice()
 {
     if (isset($_GET['action']) && $_GET['action'] == 'wc-gzdp-download') {
         $invoice = false;
         if (isset($_GET['preview']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'wc-gzdp-download')) {
             $invoice = new WC_GZDP_Invoice_Preview();
             $invoice->generate_pdf(true);
             exit;
         } else {
             if (isset($_GET['id']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'wc-gzdp-download')) {
                 $id = absint($_GET['id']);
                 $invoice = wc_gzdp_get_invoice($id);
                 if (!current_user_can('manage_woocommerce') && !current_user_can('view_order', $invoice->order)) {
                     $invoice = false;
                 }
             } else {
                 wp_die(__('Cheatin huh?', 'woocommerce-germanized-pro'));
             }
         }
         if ($invoice) {
             WC_GZDP_Download_Handler::download($invoice, isset($_GET['force']) && $_GET['force'] ? true : false);
         }
         wp_die(__('Missing permissions to download invoice', 'woocommerce-germanized-pro'));
     }
 }
        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();