WC_Order::get_downloadable_items() public WC 3.2.0
Get downloads from all line items for this order.
{} It's a method of the class: WC_Order{}
Hooks from the method
Return
Array.
Usage
$WC_Order = new WC_Order(); $WC_Order->get_downloadable_items();
Changelog
Since 3.2.0 | Introduced. |
Code of WC_Order::get_downloadable_items() WC Order::get downloadable items WC 5.0.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 );
}