WC_REST_Products_V2_Controller::get_downloads()protectedWC 1.0

Get the downloads for a product or product variation.

Метод класса: WC_REST_Products_V2_Controller{}

Хуков нет.

Возвращает

Массив.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_downloads( $product );
$product(WC_Product|WC_Product_Variation) (обязательный)
Product instance.

Код WC_REST_Products_V2_Controller::get_downloads() WC 8.7.0

protected function get_downloads( $product ) {
	$downloads = array();

	if ( $product->is_downloadable() ) {
		foreach ( $product->get_downloads() as $file_id => $file ) {
			$downloads[] = array(
				'id'   => $file_id, // MD5 hash.
				'name' => $file['name'],
				'file' => $file['file'],
			);
		}
	}

	return $downloads;
}