Automattic\WooCommerce\Internal\Orders

OrderActionsRestController::order_is_partially_refundedprivateWC 1.0

Check if a given order has any partial refunds.

Based on heuristics in the wc_create_refund()

Method of the class: OrderActionsRestController{}

Returns

true|false.

Usage

// private - for code of main (parent) class only
$result = $this->order_is_partially_refunded( $order ): bool;
$order(WC_Order) (required)
An order object.

OrderActionsRestController::order_is_partially_refunded() code WC 9.9.4

private function order_is_partially_refunded( WC_Order $order ): bool {
	$remaining_amount = $order->get_remaining_refund_amount();
	$remaining_items  = $order->get_remaining_refund_items();
	$refunds          = $order->get_refunds();
	$last_refund      = reset( $refunds );

	// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
	/** This filter is documented in includes/wc-order-functions.php */
	$partially_refunded = apply_filters(
		'woocommerce_order_is_partially_refunded',
		count( $refunds ) > 0 && ( $remaining_amount > 0 || ( $order->has_free_item() && $remaining_items > 0 ) ),
		$order->get_id(),
		$last_refund ? $last_refund->get_id() : 0
	);

	return (bool) $partially_refunded;
}