WC_REST_Product_Variations_Controller::get_downloads
Get the downloads for a product variation.
Method of the class: WC_REST_Product_Variations_Controller{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_downloads( $product, $context );
- $product(WC_Product_Variation) (required)
- Product variation instance.
- $context(string)
- Context of the request:
'view'or'edit'.
Default:'view'
WC_REST_Product_Variations_Controller::get_downloads() WC REST Product Variations Controller::get downloads code WC 10.5.0
protected function get_downloads( $product, $context = 'view' ) {
$downloads = array();
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;
}