WordPress at Your Fingertips
function is not described

WC_API_Products::save_downloadable_files() private WC 2.2

Save downloadable files

{} It's a method of the class: WC_API_Products{}

Hooks from the method
Return

WC_Product.

Usage

// private - for code of main (parent) class only
$result = $this->save_downloadable_files( $product, $downloads, $deprecated );
$product(WC_Product) (required)
-
$downloads(array) (required)
-
$deprecated(int)
Deprecated since 3.0.

Changelog

Since 2.2 Introduced.

Code of WC_API_Products::save_downloadable_files() WC 5.6.0

private function save_downloadable_files( $product, $downloads, $deprecated = 0 ) {
	if ( $deprecated ) {
		wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() does not require a variation_id anymore.' );
	}

	$files = array();
	foreach ( $downloads as $key => $file ) {
		if ( isset( $file['url'] ) ) {
			$file['file'] = $file['url'];
		}

		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;
}