WC_Product_Data_Store_CPT::update_downloads
Update downloads.
Method of the class: WC_Product_Data_Store_CPT{}
Hooks from the method
Returns
true|false. If updated or not.
Usage
// protected - for code of main (parent) or child class $result = $this->update_downloads( $product, $force );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $force(true|false)
- Force update. Used during create.
Default:false
Changelog
| Since 3.0.0 | Introduced. |
WC_Product_Data_Store_CPT::update_downloads() WC Product Data Store CPT::update downloads code WC 10.5.0
protected function update_downloads( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'downloads', $changes ) ) {
$downloads = $product->get_downloads();
$meta_values = array();
if ( $downloads ) {
foreach ( $downloads as $key => $download ) {
// Store in format WC uses in meta.
$meta_values[ $key ] = $download->get_data();
}
}
if ( $product->is_type( ProductType::VARIATION ) ) {
do_action( 'woocommerce_process_product_file_download_paths', $product->get_parent_id(), $product->get_id(), $downloads );
} else {
do_action( 'woocommerce_process_product_file_download_paths', $product->get_id(), 0, $downloads );
}
return $this->update_or_delete_post_meta( $product, '_downloadable_files', wp_slash( $meta_values ) );
}
return false;
}