Remember downloadable files (#44008)
* The previously uploaded file should re-appear when the product changes from downloadable to not and then back again * Add changelog file * Fix php linter error
This commit is contained in:
parent
2acbb3d3fb
commit
9f3c7885a4
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: tweak
|
||||
|
||||
The previously uploaded file should re-appear when the product changes from downloadable to not and then back again
|
|
@ -1561,6 +1561,31 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
|||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the downloads for a product.
|
||||
*
|
||||
* @param WC_Product $product Product instance.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_downloads( $product ) {
|
||||
$downloads = array();
|
||||
|
||||
$context = isset( $this->request ) && isset( $this->request['context'] ) ? $this->request['context'] : 'view';
|
||||
|
||||
if ( $product->is_downloadable() || 'edit' === $context ) {
|
||||
foreach ( $product->get_downloads() as $file_id => $file ) {
|
||||
$downloads[] = array(
|
||||
'id' => $file_id, // MD5 hash.
|
||||
'name' => $file['name'],
|
||||
'file' => $file['file'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $downloads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product data.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue