WC_Order_Item_Product::get_item_downloads()

Get any associated downloadable files.


Description Description


Return Return

(array)


Top ↑

Source Source

File: includes/class-wc-order-item-product.php

	public function get_item_downloads() {
		$files      = array();
		$product    = $this->get_product();
		$order      = $this->get_order();
		$product_id = $this->get_variation_id() ? $this->get_variation_id() : $this->get_product_id();

		if ( $product && $order && $product->is_downloadable() && $order->is_download_permitted() ) {
			$email_hash         = function_exists( 'hash' ) ? hash( 'sha256', $order->get_billing_email() ) : sha1( $order->get_billing_email() );
			$data_store         = WC_Data_Store::load( 'customer-download' );
			$customer_downloads = $data_store->get_downloads(
				array(
					'user_email' => $order->get_billing_email(),
					'order_id'   => $order->get_id(),
					'product_id' => $product_id,
				)
			);
			foreach ( $customer_downloads as $customer_download ) {
				$download_id = $customer_download->get_download_id();

				if ( $product->has_file( $download_id ) ) {
					$file                  = $product->get_file( $download_id );
					$files[ $download_id ] = $file->get_data();
					$files[ $download_id ]['downloads_remaining'] = $customer_download->get_downloads_remaining();
					$files[ $download_id ]['access_expires']      = $customer_download->get_access_expires();
					$files[ $download_id ]['download_url']        = add_query_arg(
						array(
							'download_file' => $product_id,
							'order'         => $order->get_order_key(),
							'uid'           => $email_hash,
							'key'           => $download_id,
						),
						trailingslashit( home_url() )
					);
				}
			}
		}

		return apply_filters( 'woocommerce_get_item_downloads', $files, $this, $order );
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.