What’s the hook after the order is refunded via the refund button referenced in the screenshot?

WooCommerce order refund

The answer is “woocommerce_order_refunded”. Located inside woocommerce/includes/wc-order-functions.php L627 as of version 5.9.0. You can use this hook to do something when the WooCommerce order is refunded

Example:

add_action( 'woocommerce_order_refunded', 'after_refund', 10, 2 );

function after_refund( $order_id, $refund_id ) {
	// Do something.
}


That’s all.

However, refunds in payment gateways are not handled via this hook. If you’re extending “WC_Payment_Gateway” to create a custom payment gateway and using the “woocommerce_order_refunded” hook to process the refund, then you’re __DOING_IT_WRONG__.

When you’re extending the ” WC_Payment_Gateway ” class you’ll need to override the variable and function to perform the refund.

$supports variable

/**
 * Supported features such as 'default_credit_card_form', 'refunds'.
 *
 * @var array
 */
public $supports = array( 'products', 'refunds' );


then utilizes the process_refund function to handle the actual refunding.

Here’s the process_refund in abstract class.

/**
 * Process refund.
 *
 * If the gateway declares 'refunds' support, this will allow it to refund.
 * a passed in amount.
 *
 * @param  int        $order_id Order ID.
 * @param  float|null $amount Refund amount.
 * @param  string     $reason Refund reason.
 * @return boolean True or false based on success, or a WP_Error object.
 */
public function process_refund( $order_id, $amount = null, $reason = '' ) {
	return false;
}


I hope this helps! You might want to allow your customers to delete their own accounts.

WooCommerce hook after the order is refunded from the admin panel
Tagged on:

Sanjeev Aryal

Don't bury your thoughts, put your vision into reality ~ Bob Marley.

Leave a Reply

Your email address will not be published.

Pin It on Pinterest