Automattic\WooCommerce\Internal\Fulfillments

FulfillmentUtils::get_pending_itemspublic staticWC 1.0

Get pending items for an order.

Method of the class: FulfillmentUtils{}

No Hooks.

Returns

Array. An array of pending items.

Usage

$result = FulfillmentUtils::get_pending_items( $order, $fulfillments, $without_refunds ): array;
$order(WC_Order) (required)
The order object.
$fulfillments(array) (required)
An array of fulfillments to check.
$without_refunds(true|false)
Whether to exclude refunded items from the pending items.
Default: true

FulfillmentUtils::get_pending_items() code WC 10.3.3

public static function get_pending_items( WC_Order $order, $fulfillments, $without_refunds = true ): array {
	$items_in_fulfillments = self::get_all_items_of_fulfillments( $fulfillments );
	$order_items           = array_map(
		function ( $item ) use ( $order, $without_refunds ) {
			// Refunded item quantities are saved as negative values in the order.
			return array(
				'item_id' => $item->get_id(),
				'item'    => $item,
				'qty'     => $item->get_quantity() + ( $without_refunds ? $order->get_qty_refunded_for_item( $item->get_id() ) : 0 ),
			);
		},
		$order->get_items() ?? array()
	);

	// If there are items in fulfillments, subtract their quantities from the order items.
	if ( ! empty( $items_in_fulfillments ) ) {
		foreach ( $order_items as $item_id => &$item ) {
			if ( isset( $items_in_fulfillments[ $item_id ] ) ) {
				$item['qty'] = $item['qty'] - $items_in_fulfillments[ $item_id ];
			}
		}
	}

	return array_filter(
		$order_items,
		function ( $item ) {
			return $item['qty'] > 0; // Only return items with a positive quantity.
		}
	);
}