WC_Order::get_downloadable_items()publicWC 3.2.0

Get downloads from all line items for this order.

Method of the class: WC_Order{}

Return

Array.

Usage

$WC_Order = new WC_Order();
$WC_Order->get_downloadable_items();

Changelog

Since 3.2.0 Introduced.

WC_Order::get_downloadable_items() code WC 8.7.0

public function get_downloadable_items() {
	$downloads = array();

	foreach ( $this->get_items() as $item ) {
		if ( ! is_object( $item ) ) {
			continue;
		}

		// Check item refunds.
		$refunded_qty = abs( $this->get_qty_refunded_for_item( $item->get_id() ) );
		if ( $refunded_qty && $item->get_quantity() === $refunded_qty ) {
			continue;
		}

		if ( $item->is_type( 'line_item' ) ) {
			$item_downloads = $item->get_item_downloads();
			$product        = $item->get_product();
			if ( $product && $item_downloads ) {
				foreach ( $item_downloads as $file ) {
					$downloads[] = array(
						'download_url'        => $file['download_url'],
						'download_id'         => $file['id'],
						'product_id'          => $product->get_id(),
						'product_name'        => $product->get_name(),
						'product_url'         => $product->is_visible() ? $product->get_permalink() : '', // Since 3.3.0.
						'download_name'       => $file['name'],
						'order_id'            => $this->get_id(),
						'order_key'           => $this->get_order_key(),
						'downloads_remaining' => $file['downloads_remaining'],
						'access_expires'      => $file['access_expires'],
						'file'                => array(
							'name' => $file['name'],
							'file' => $file['file'],
						),
					);
				}
			}
		}
	}

	return apply_filters( 'woocommerce_order_get_downloadable_items', $downloads, $this );
}