WC_Product_Data_Store_CPT::read_downloads()
Read downloads from post meta.
Method of the class: WC_Product_Data_Store_CPT{}
Hooks from the method
Return
null
. Nothing (null).
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. |
WC_Product_Data_Store_CPT::read_downloads() WC Product Data Store CPT::read downloads code WC 9.3.1
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 ); } }