WC_REST_Product_Variations_Controller::get_downloads()protectedWC 1.0

Get the downloads for a product variation.

Method of the class: WC_REST_Product_Variations_Controller{}

No Hooks.

Return

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() code WC 9.5.1

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;
}