WC_API_Products::get_downloads()privateWC 2.1

Get the downloads for a product or product variation

Method of the class: WC_API_Products{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_downloads( $product );
$product(WC_Product|WC_Product_Variation) (required)
-

Changelog

Since 2.1 Introduced.

WC_API_Products::get_downloads() code WC 8.7.0

private function get_downloads( $product ) {

	$downloads = array();

	if ( $product->is_downloadable() ) {

		foreach ( $product->get_downloads() as $file_id => $file ) {

			$downloads[] = array(
				'id'   => $file_id, // do not cast as int as this is a hash
				'name' => $file['name'],
				'file' => $file['file'],
			);
		}
	}

	return $downloads;
}