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

How to Add Custom Bulk Actions to WooCommerce Admin Order List?

When it comes to managing WooCommerce orders, bulk actions can help the process by allowing users to update order status, send emails, or perform other tasks. However, the default actions may not always fit specific needs. For example, as a store owner, you might find the need to create a custom action for marking orders as “shipped”, “generate invoice”, or “refund” multiple orders collectively. This can be easily done with WooCommerce bulk actions, making it a highly efficient tool for managing orders and saving time.

This post will guide you on how to add custom bulk actions to the WooCommerce admin order list.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Solution: Add Custom Bulk Actions to WooCommerce Admin Order List

Consider an online shoe store that is experiencing a surge in orders during the holiday season. To align the shipping process and reduce manual effort, the store manager decided to implement a custom bulk action called “Mark Shipped” for the order management page.

With the below code snippet, the store manager can create custom bulk actions on the admin order list page.

function ts_custom_bulk_action_mark_shipped() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            if ($('select[name="action"]').length > 0) {
                $('<option>')
                    .val('mark_shipped')
                    .text('<?php _e('Mark Shipped', 'text-domain'); ?>')
                    .appendTo('select[name="action"]');
            }

            if ($('select[name="action2"]').length > 0) {
                $('<option>')
                    .val('mark_shipped')
                    .text('<?php _e('Mark Shipped', 'text-domain'); ?>')
                    .appendTo('select[name="action2"]');
            }
        });
    </script>
    <?php
}

add_action('admin_footer', 'ts_custom_bulk_action_mark_shipped');

Output

The below output demonstrates that the new custom bulk action i.e. “Mark Shipped” has been added to the dropdown list and “Shipped” is added as a custom order status.

How to Add Custom Bulk Actions to WooCommerce Admin Order List? - Tyche Softwares

Code Explanation

Here is the explanation of the code step by step:-

Function Declaration

This line declares a custom function named ts_custom_bulk_action_mark_shipped. This function will be used to add a custom bulk action to the WordPress admin panel.

JavaScript Code block

This is a block of JavaScript code enclosed in <script> tags. It uses jQuery to manipulate the DOM (Document Object Model) when the document is ready.

  • jQuery(document).ready(function() { … });: This ensures that the JavaScript code inside is executed when the document (admin page) is fully loaded.
  • jQuery(‘<option>’): Creates a new <option> element.
  • .val(‘mark_shipped’): Sets the value attribute of the <option> to ‘mark_shipped‘.
  • .text(‘<?php _e(‘Mark Shipped’, ‘text-domain’); ?>’): Sets the text content of the <option> to the translated string ‘Mark Shipped’. The _e() function is used for translating strings in WordPress, and it takes the text and a text domain as parameters.
  • .appendTo(‘select[name=”action1″], select[name=”action2″]’): Appends the created <option> to the specified <select> elements with the given names. In this case, it adds the option to the bulk action dropdowns on the admin panel.

Hooking the function

This line hooks the ts_custom_bulk_action_mark_shipped function to the admin_footer action in WordPress. The admin_footer action is fired in the footer of all admin pages after the main content, allowing you to insert additional scripts or content.

Conclusion

By using the code snippet provided above, you can add a custom bulk action called “Mark Shipped” to the dropdown list of bulk actions on the admin order list page. However, the default WooCommerce order status may not be enough for you to keep consumers in the loop about the order status and improve customer satisfaction. The Custom Order Status plugin lets you create custom order statuses and notify the corresponding user & admins.

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

Share It:

Subscribe
Notify of
3 Comments
Newest
Oldest
Inline Feedbacks
View all comments
conhe
5 months ago

Hello, This is a nice idea ! Can you expand on the bulk refund ? I can’t figure out how to do it. I want to be able to select all the desired orders and automatically fully refund them. Wha should I write ? Thank you

Editor
5 months ago
Reply to  conhe

Hi Conhe,

We’ve written a new post based on your request. Please check it out here: ‘How to Refund Multiple Orders (via Bulk Actions) in WooCommerce (Compatible with HPOS Order Tables).’ 

conhe
5 months ago
Reply to  Saranya

Thank you ! Will have a look

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