WC_Abstract_Order::get_item
Get an order item object, based on its type.
Method of the class: WC_Abstract_Order{}
No Hooks.
Returns
WC_Order_Item|false.
Usage
$WC_Abstract_Order = new WC_Abstract_Order(); $WC_Abstract_Order->get_item( $item_id, $load_from_db );
- $item_id(int) (required)
- ID of item to get.
- $load_from_db(true|false)
- Prior to 3.2 this item was loaded direct from WC_Order_Factory, not this object. This param is here for backwards compatibility with that. If false, uses the local items variable instead.
Default: true
Changelog
| Since 3.0.0 | Introduced. |
WC_Abstract_Order::get_item() WC Abstract Order::get item code WC 10.4.3
public function get_item( $item_id, $load_from_db = true ) {
if ( $load_from_db ) {
return WC_Order_Factory::get_order_item( $item_id );
}
// Search for item id.
if ( $this->items ) {
foreach ( $this->items as $group => $items ) {
if ( isset( $items[ $item_id ] ) ) {
return $items[ $item_id ];
}
}
}
// Load all items of type and cache.
$type = $this->data_store->get_order_item_type( $this, $item_id );
if ( ! $type ) {
return false;
}
$items = $this->get_items( $type );
return ! empty( $items[ $item_id ] ) ? $items[ $item_id ] : false;
}