WC_REST_Products_V1_Controller::save_downloadable_files()
Save downloadable files.
Method of the class: WC_REST_Products_V1_Controller{}
Hooks from the method
Return
WC_Product
.
Usage
// protected - for code of main (parent) or child class $result = $this->save_downloadable_files( $product, $downloads, $deprecated );
- $product(WC_Product) (required)
- Product instance.
- $downloads(array) (required)
- Downloads data.
- $deprecated(int)
- Deprecated since 3.0.
WC_REST_Products_V1_Controller::save_downloadable_files() WC REST Products V1 Controller::save downloadable files code WC 9.7.1
protected function save_downloadable_files( $product, $downloads, $deprecated = 0 ) { if ( $deprecated ) { wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.' ); } $files = array(); foreach ( $downloads as $key => $file ) { if ( empty( $file['file'] ) ) { continue; } $download = new WC_Product_Download(); $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); $files[] = $download; } $product->set_downloads( $files ); return $product; }