WC_Abstract_Order::get_items
Return an array of items/products within this order.
Method of the class: WC_Abstract_Order{}
Hooks from the method
Returns
WC_Order_Item[].
Usage
$WC_Abstract_Order = new WC_Abstract_Order(); $WC_Abstract_Order->get_items( $types );
- $types(string|array)
- Types of line items to get (array or string).
Default:'line_item'
WC_Abstract_Order::get_items() WC Abstract Order::get items code WC 11.0.1
public function get_items( $types = 'line_item' ) {
$items = array();
$types = array_filter( (array) $types );
foreach ( $types as $type ) {
$group = $this->type_to_group( $type );
if ( $group ) {
if ( ! isset( $this->items[ $group ] ) ) {
$read_items = array_filter( $this->data_store->read_items( $this, $type ) );
// Prime the product cache to ensure that methods such as needs_processing, get_downloadable_items, and has_downloadable_item run
// on warm post meta caches for products. This addresses scenarios where the order object was not populated during a batch population.
if ( 'line_item' === $type && ! empty( $read_items ) ) {
$product_ids = array_map( static fn( $item ) => $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id(), $read_items );
_prime_post_caches( array_unique( array_filter( $product_ids ) ) );
}
// Set the back-reference to the parent order on each loaded item.
array_walk( $read_items, fn( $item ) => $item instanceof WC_Order_Item && $item->set_order( $this ) );
$this->items[ $group ] = $read_items;
}
// Don't use array_merge here because keys are numeric.
$items = $items + $this->items[ $group ];
}//end if
}
return apply_filters( 'woocommerce_order_get_items', $items, $this, $types );
}