Handle digital downloads.
Author: WooThemes
 /**
  * Admin voucher download, which will work regardless of the download
  * permissions/current user, and will not count towards the download
  * count
  *
  * @since 2.1
  */
 public function download_voucher()
 {
     if (isset($_GET['post']) && isset($_GET['product_id']) && isset($_GET['item_id']) && isset($_GET['action']) && 'download' == $_GET['action'] && $_GET['voucher_id']) {
         $order = wc_get_order($_GET['post']);
         $items = $order->get_items();
         $voucher = new WC_Voucher($_GET['voucher_id'], $_GET['post'], $items[$_GET['item_id']], $_GET['item_id']);
         $download_handler = new WC_Download_Handler();
         $file_path = $voucher->get_voucher_full_filename(WC_PDF_Product_Vouchers::get_uploads_path());
         if ('redirect' === get_option('woocommerce_file_download_method')) {
             $file_path = $voucher->convert_path_to_url($file_path);
         }
         $download_handler->download($file_path, $_GET['product_id']);
         exit;
     }
 }
/**
 * @deprecated
 */
function woocommerce_readfile_chunked($file, $retbytes = true)
{
    _deprecated_function('woocommerce_readfile_chunked', '2.1', 'WC_Download_Handler::readfile_chunked()');
    return WC_Download_Handler::readfile_chunked($file);
}
     *
     * IE bug prevents download via SSL when Cache Control and Pragma no-cache headers set.
     *
     * @param array $headers
     * @return array
     */
    public static function ie_nocache_headers_fix($headers)
    {
        if (is_ssl() && !empty($GLOBALS['is_IE'])) {
            $headers['Cache-Control'] = 'private';
            unset($headers['Pragma']);
        }
        return $headers;
    }
    /**
     * Die with an error message if the download fails.
     * @param  string $message
     * @param  string  $title
     * @param  integer $status
     * @access private
     */
    private static function download_error($message, $title = '', $status = 404)
    {
        if (!strstr($message, '<a ')) {
            $message .= ' <a href="' . esc_url(wc_get_page_permalink('shop')) . '" class="wc-forward">' . __('Go to shop', 'woocommerce') . '</a>';
        }
        wp_die($message, $title, array('response' => $status));
    }
}
WC_Download_Handler::init();