WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::read_downloads() protected WC 3.0.0

Read downloads from post meta.

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

Hooks from the method

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->read_downloads( $product );
$product(WC_Product) (required) (passed by reference — &)
Product object.

Changelog

Since 3.0.0 Introduced.

Code of WC_Product_Data_Store_CPT::read_downloads() WC 5.8.0

protected function read_downloads( &$product ) {
	$meta_values = array_filter( (array) get_post_meta( $product->get_id(), '_downloadable_files', true ) );

	if ( $meta_values ) {
		$downloads = array();
		foreach ( $meta_values as $key => $value ) {
			if ( ! isset( $value['name'], $value['file'] ) ) {
				continue;
			}
			$download = new WC_Product_Download();
			$download->set_id( $key );
			$download->set_name( $value['name'] ? $value['name'] : wc_get_filename_from_url( $value['file'] ) );
			$download->set_file( apply_filters( 'woocommerce_file_download_path', $value['file'], $product, $key ) );
			$downloads[] = $download;
		}
		$product->set_downloads( $downloads );
	}
}