public function orderItemById($item_id, \WC_Abstract_Order $WC_Order = null)
    {
        if (!($item_id = (int) $item_id)) {
            return []; // Not possible.
        } elseif (!($WC_Order = $WC_Order ?: $this->orderByItemId($item_id))) {
            return []; // Not possible.
        }
        foreach ($WC_Order->get_items() as $_item_id => $_WC_Order_Item) {
            if ($_item_id === $item_id) {
                // WC 3.0+ uses `\WC_Order_Item`.
                // <https://docs.woocommerce.com/wc-apidocs/class-WC_Abstract_Order.html>
                // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html>
                return $_WC_Order_Item; // `\WC_Order_Item|array`.
            }
        } // unset($_item_id, $_WC_Order_Item); // Housekeeping.

        return []; // Failure.
    }
public function orderItemById($item_id, \WC_Abstract_Order $WC_Order = null)
    {
        if (!($item_id = (int) $item_id)) {
            return []; // Not possible.
        } elseif (!($WC_Order = $WC_Order ?: $this->orderByItemId($item_id))) {
            return []; // Not possible.
        }
        foreach ($WC_Order->get_items() as $_item_id => $_WC_Order_Item) {
            if ($_item_id === $item_id) {
                // WC 3.0+ uses `\WC_Order_Item`.
                // <https://docs.woocommerce.com/wc-apidocs/class-WC_Abstract_Order.html>
                // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html>
                return $_WC_Order_Item; // `\WC_Order_Item|array`.
            }
        } // unset($_item_id, $_WC_Order_Item); // Housekeeping.

        return []; // Failure.
    }
public function orderItemById ( $ item_id , \ WC_Abstract_Order $ WC_Order = null ) { if ( ! ( $ item_id = ( int ) $ item_id ) ) { return [ ] ; // Not possible. } elseif ( ! ( $ WC_Order = $ WC_Order ? : $ this -> orderByItemId ( $ item_id ) ) ) { return [ ] ; // Not possible. } foreach ( $ WC_Order -> get_items ( ) as $ _item_id => $ _WC_Order_Item ) { if ( $ _item_id === $ item_id ) { // WC 3.0+ uses `\WC_Order_Item`. // <https://docs.woocommerce.com/wc-apidocs/class-WC_Abstract_Order.html> // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html> return $ _WC_Order_Item ; // `\WC_Order_Item|array`. } } // unset($_item_id, $_WC_Order_Item); // Housekeeping. return [ ] ; // Failure. }
Get order item by ID.

@since 160608 Order item utilities.

@param string|int              $item_id  Order item ID.
@param \WC_Abstract_Order|null $WC_Order The order if already known.

@return \WC_Order_Item|array An order item, else empty array.
Get order item by ID .