wc_order_fully_refunded()WC 2.4

When refunding an order, create a refund line item if the partial refunds do not match order total.

This is manual; no gateway refund will be performed.

No Hooks.

Return

null. Nothing (null).

Usage

wc_order_fully_refunded( $order_id );
$order_id(int) (required)
Order ID.

Changelog

Since 2.4 Introduced.

wc_order_fully_refunded() code WC 9.4.2

function wc_order_fully_refunded( $order_id ) {
	$order      = wc_get_order( $order_id );
	$max_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded() );

	if ( ! $max_refund ) {
		return;
	}

	// Create the refund object.
	wc_switch_to_site_locale();
	wc_create_refund(
		array(
			'amount'     => $max_refund,
			'reason'     => __( 'Order fully refunded.', 'woocommerce' ),
			'order_id'   => $order_id,
			'line_items' => array(),
		)
	);
	wc_restore_locale();

	$order->add_order_note( __( 'Order status set to refunded. To return funds to the customer you will need to issue a refund through your payment gateway.', 'woocommerce' ) );
}