Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)?

In WooCommerce, the default refund status available on the edit order page works well for changing a single order to refund status. But you might also be required to change the status of multiple orders to refund status. Currently, the bulk actions dropdown on the WooCommerce > Orders page which provides several bulk actions but doesn’t include actions, such as changing multiple orders to the “Refunded” status.


In this post, we will see how to change multiple orders to refund status via the Bulk actions dropdown.

Solution: How to Refund Multiple Orders (via Bulk Actions) in WooCommerce

The code snippet will add an option named “Change status to Refunded” to the bulk actions dropdown on the WooCommerce Orders page. This option allows administrators to refund multiple orders simultaneously.

// Updating label in admin order list bulk actions dropdown
function ts_update_custom_dropdown_bulk_actions_shop_order( $actions ) {

// Add default WooCommerce 'mark_refunded' action
$actions['mark_refunded'] = __( 'Change status to Refunded', 'woocommerce' );

return $actions;
}
add_action('bulk_actions-edit-shop_order', 'ts_update_custom_dropdown_bulk_actions_shop_order');
add_filter( 'bulk_actions-woocommerce_page_wc-orders', 'ts_update_custom_dropdown_bulk_actions_shop_order', 20, 1 );
add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', 'ts_update_custom_dropdown_bulk_actions_shop_order', 20, 1 );
flexi bogo cta banner image


This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…

BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?

Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.

Output

By adding the “Change status to Refunded” option to the bulk actions dropdown, admins can quickly mark multiple orders for refunds all at once, making it easier to handle refunds without doing each one separately.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares

When the refund action is applied to multiple orders, the code also triggers the default “Refunded” process that happens on the edit orders page and adjusts the total costs accordingly.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares

The above code to change multiple orders to refund status is also compatible with HPOS Order Tables.

Solution: Automatically Refund Multiple WooCommerce Orders when Using PayPal Payment Gateway

Most WordPress site owners prefer to use the most popular payment gateways like PayPal to streamline transactions into their woocommerce site. When such payment options are set up on your site then you might need customizations to automate tasks, such as refunding bulk orders.

For instance, if you need to refund multiple orders paid via PayPal, doing it manually from the WooCommerce edit order page is a daunting task. So in this WooCommerce customization, we will provide a solution that will automate the refund for multiple orders in PayPal transactions. Also, the provided code snippet ensures that it works in both WordPress posts table and HPOS orders Tables.

use function WooCommerce\PayPalCommerce\Api\ppcp_refund_order;

// Updating label in admin order list bulk actions dropdown
function ts_update_custom_dropdown_bulk_actions_shop_order( $actions ) {
    // Add default WooCommerce 'mark_refunded' action
    $actions['mark_refunded'] = __( 'Change status to Refunded', 'woocommerce' );
    return $actions;
}
add_action('bulk_actions-edit-shop_order', 'ts_update_custom_dropdown_bulk_actions_shop_order');
add_filter( 'bulk_actions-woocommerce_page_wc-orders', 'ts_update_custom_dropdown_bulk_actions_shop_order', 20, 1 );

// Handling the custom bulk action
function ts_handle_custom_bulk_actions_shop_order( $redirect_to, $doaction, $order_ids ) {
    if ( $doaction === 'mark_refunded' && ! empty( $order_ids ) ) {
        foreach ( $order_ids as $order_id ) {
            $order = wc_get_order( $order_id );
            if ( $order && $order->get_status() !== 'refunded' ) {
                // Update the order status to "refunded"
                $order->update_status( 'refunded' );
            }
        }
    }
    return $redirect_to;
}
add_filter( 'handle_bulk_actions-edit-shop_order', 'ts_handle_custom_bulk_actions_shop_order', 20, 3 );

// Hook to handle automatic refunds when status changes to "refunded"
add_action( 'woocommerce_order_status_changed', 'ts_auto_refund_on_status_change', 10, 4 );

function ts_auto_refund_on_status_change( $order_id, $old_status, $new_status, $order ) {
    if ( $new_status === 'refunded' ) {
        if ( $order->get_payment_method() === 'ppcp-gateway' ) {
            $refund_amount = $order->get_total();
            $refund_response = ppcp_refund_order( $order, $refund_amount );
           
        }
    }
}

Output

Let’s consider that you need to refund some bulk  WooCommerce orders paid via the PayPal payment gateway. The below image shows a list of orders currently in ‘Processing’ status, indicating they’ve been completed using real payment methods like PayPal.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares

At this point, when an order is completed in WooCommerce, the payment transaction status of these orders in the PayPal test store will be in ‘completed’ status.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares

Let’s change the status of the WooCommerce orders to ‘refunded’ status using the bulk action ‘Change status to Refunded’ option in WooCommerce > Orders page.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares
Once the status is set to ‘refunded’ on the WooCommerce orders page, the refund process will automatically be initiated and applies a full refund in the PayPal’s transaction activity.

How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables)? - Tyche Softwares
Here is the detailed walk-through of the video of how to handle bulk refunds in WooCommerce.

Interested in exploring another useful feature that most admins prefer? You can filter WooCommerce orders by multiple statuses, which could be a game-changer for managing your daily tasks!

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
11 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Philip
3 months ago

Thank you very much, this code snippet helped me with my bulk refunding through paypal gateway in Woocommerce. I just added it by using the “Code Snippets”-Plugin under the “functions” section. super easy 🙂

conhe
3 months ago

Hello and thank you for this snippet, will it refund the full amount of the order (all the products + shipping + taxes) for the selected orders ?

Edit : sorry, I’ve added the code and nothing appears in the dropdown. WOP is up to date as all plugins

Last edited 3 months ago by conhe
conhe
3 months ago
Reply to  Saranya

Hi Saranya and thank you for your answer. I tried but nothing works.. So, I took the code from ( https://www.tychesoftwares.com/how-to-add-custom-bulk-actions-to-woocommerce-admin-order-list/ ) and modified it with mark_refunded and it works great though

conhe
3 months ago
Reply to  Saranya

Update : it doesn’t “really” work as it didn’t refunded the customer. I have to go on paypal and do it myself. This is a manual refund and not an automatic. Any idea how to turn it automatic ?

conhe
3 months ago
Reply to  Saranya

Hello Saranya, sure thing. Since, this wasn’t working (nothing was appearing in the bulk action menu) : // Updating label in admin order list bulk actions dropdown function ts_update_custom_dropdown_bulk_actions_shop_order( $actions ) {   // Add default WooCommerce 'mark_refunded' action   $actions['mark_refunded'] = __( 'Change status to Refunded', 'woocommerce' );   return $actions; } add_filter( 'bulk_actions-woocommerce_page_wc-orders', 'ts_update_custom_dropdown_bulk_actions_shop_order', 20, 1 ); add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', 'ts_update_custom_dropdown_bulk_actions_shop_order', 20, 1 ); I’ve added this : function ts_custom_bulk_action_mark_refunded() {   ?>   <script type="text/javascript">     jQuery(document).ready(function($) {       if ($('select[name="action"]').length > 0) {         $('<option>')           .val('mark_refunded')           .text('<?php _e('Change status to Refunded', 'snippet'); ?>')           .appendTo('select[name="action"]');       }       if ($('select[name="action2"]').length > 0) {         $('<option>')           .val('mark_refunded')           .text('<?php _e('Change status… Read more »

conhe
3 months ago
Reply to  Saranya

Hello Saranya and thank you for your time. I’ll have a look at HPOS since we deactivated it because of some other stuff. I’ll see if I can reactivate it.

Thank you !

11
0
Would love your thoughts, please comment.x
()
x