admin管理员组

文章数量:1122832

I am using Woocommerce plugin for my custom product .and I am stuck with a situation .

Does Woo commerce provide any hook or filter when refund is done through admin panel and refund will be manually.

I am using Woocommerce plugin for my custom product .and I am stuck with a situation .

Does Woo commerce provide any hook or filter when refund is done through admin panel and refund will be manually.

Share Improve this question asked Jul 28, 2017 at 10:59 user1263829user1263829 1111 silver badge3 bronze badges 1
  • 2 When that button is clicked, javascript is called to update the UI to show refund options. It will not trigger any hook. Do you mean to ask if any hooks are triggered when such a refund is confirmed? – Joshua Goossen Commented Aug 30, 2017 at 16:41
Add a comment  | 

3 Answers 3

Reset to default 14

Although this answer is little late but anyone else may get benefit from it. The woocommerce_order_refunded hook is called when an order is refunded. Use the following example:

// add the action 
add_action( 'woocommerce_order_refunded', 'action_woocommerce_order_refunded', 10, 2 ); 
// Do the magic
function action_woocommerce_order_refunded( $order_id, $refund_id ) 
{ 
  // Your code here
}

My answer is for emails or when refunds are done through the payment gateway but it might help someone coming across this. So in addition to Tech Dog's answer You can use a few other hooks specifically for partial refunds: woocommerce_order_partially_refunded and for full refunds: woocommerce_order_fully_refunded

These hooks can be seen here (I copied the lines at version 5.9 of WooCommerce, so depending on when someone is reading this the hooks might be on different lines in the latest version)

In the latest version of WooCommerce the following hooks are fired when an order is refunded:

  1. Either woocommerce_order_fully_refunded or woocommerce_order_partially_refunded hook
  2. A bunch of hooks which are always fired when an order status is changed, you can find them here https://rudrastyh.com/woocommerce/order-lifecycle-hooks.html#order-status-changed
  3. and the last one woocommerce_order_refunded

p.s. I mentioned the hooks in the same order they are going to be fired.

Example 1:

add_action( 'woocommerce_order_fully_refunded', function( $order_id, $refund_id ) {

    // enter your code here

}, 20, 2 );

Example 2:

add_action( 'woocommerce_order_partially_refunded', function( $order_id, $refund_id ) {
    
        // enter your code here
    
}, 20, 2 );

Example 3:

add_action( 'woocommerce_order_refunded', function( $order_id, $refund_id ) {
        
     // enter your code here
        
}, 20, 2 );

As you can see all of them have the same arguments

本文标签: Are there any hook or filter when refund is done through admin woocommerce