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 );
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.
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.
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.
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.
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.
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.
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!
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 🙂
Hi Philip,
Glad to hear that the code snippet was helpful to you!
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
Hi Conhe, The code has been tested in the updated WooCommerce version (9.0.0) and it is working fine. Please try once again after deactivating all other plugins except WooCommerce and switching to a default WordPress theme to avoid any plugin/theme conflicts. As for your question about refunding the full order amount (products, shipping, taxes) for the selected orders? Yes, It refunds everything. Also, the refund action will work in exactly same way as it works on the WooCommerce single order page, please take a look at this screenshot for reference. https://prnt.sc/hVWsCKXSz78J Hope it works or else get back to us… Read more »
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
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 ?
Hi Conhe,
To better assist you, could you please share the code you modified?
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 »
Hi Conhe, The reason that the bulk action option wasn’t appearing in the dropdown with the first code might be because HPOS (High-Performance Order Storage) might not enabled on your site. The code has been updated to support both WordPress posts and HPOS Order Tables. Also, we have updated the post that will automate a full refund in PayPal when multiple orders are changed to refunded status using the bulk action dropdown. Please try the code snippet below the heading ‘Automatically Refund Multiple WooCommerce Orders when Using Paypal Payment Gateway’ and feel free to reach out if you require further… Read more »
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 !
Hi Conhe,
You’re most welcome! When you reactivate the HPOS let me know if it goes well or anything else we can help with.