WC_Order_Factory::get_order_item( int $item_id )
Get order item.
Description Description
Parameters Parameters
- $item_id
-
(Required) Order item ID to get.
Return Return
(WC_Order_Item|false) if not found
Source Source
File: includes/class-wc-order-factory.php
public static function get_order_item( $item_id = 0 ) { if ( is_numeric( $item_id ) ) { $item_type = WC_Data_Store::load( 'order-item' )->get_order_item_type( $item_id ); $id = $item_id; } elseif ( $item_id instanceof WC_Order_Item ) { $item_type = $item_id->get_type(); $id = $item_id->get_id(); } elseif ( is_object( $item_id ) && ! empty( $item_id->order_item_type ) ) { $id = $item_id->order_item_id; $item_type = $item_id->order_item_type; } else { $item_type = false; $id = false; } if ( $id && $item_type ) { $classname = false; switch ( $item_type ) { case 'line_item': case 'product': $classname = 'WC_Order_Item_Product'; break; case 'coupon': $classname = 'WC_Order_Item_Coupon'; break; case 'fee': $classname = 'WC_Order_Item_Fee'; break; case 'shipping': $classname = 'WC_Order_Item_Shipping'; break; case 'tax': $classname = 'WC_Order_Item_Tax'; break; } $classname = apply_filters( 'woocommerce_get_order_item_classname', $classname, $item_type, $id ); if ( $classname && class_exists( $classname ) ) { try { return new $classname( $id ); } catch ( Exception $e ) { return false; } } } return false; }