WC_Download_Handler::download()
Download a file - hook into init function.
Method of the class: WC_Download_Handler{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$result = WC_Download_Handler::download( $file_path, $product_id );
- $file_path(string) (required)
- URL to file.
- $product_id(int) (required)
- Product ID of the product being downloaded.
WC_Download_Handler::download() WC Download Handler::download code WC 9.3.3
public static function download( $file_path, $product_id ) { if ( ! $file_path ) { self::download_error( __( 'No file defined', 'woocommerce' ) ); } $filename = basename( $file_path ); if ( strstr( $filename, '?' ) ) { $filename = current( explode( '?', $filename ) ); } $filename = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id ); /** * Filter download method. * * @since 4.5.0 * @param string $method Download method. * @param int $product_id Product ID. * @param string $file_path URL to file. */ $file_download_method = apply_filters( 'woocommerce_file_download_method', get_option( 'woocommerce_file_download_method', 'force' ), $product_id, $file_path ); // Add action to prevent issues in IE. add_action( 'nocache_headers', array( __CLASS__, 'ie_nocache_headers_fix' ) ); // Trigger download via one of the methods. do_action( 'woocommerce_download_file_' . $file_download_method, $file_path, $filename ); }