WC_REST_Products_V4_Controller::get_downloads
Get the downloads for a product.
Method of the class: WC_REST_Products_V4_Controller{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_downloads( $product );
- $product(WC_Product) (required)
- Product instance.
WC_REST_Products_V4_Controller::get_downloads() WC REST Products V4 Controller::get downloads code WC 10.3.6
woocommerce/includes/rest-api/Controllers/Version4/Products/class-wc-rest-products-v4-controller.php
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;
}