How-To-Filter-Woocommerce-Orders-By-Multiple-Order-Statuses

How to Filter WooCommerce Orders by Multiple Order Statuses: A Beginner’s Guide

WooCommerce makes it easy to manage your online store, but sometimes you need to get *really* specific with your order data. One common requirement is filtering orders by multiple order statuses. Imagine you want to quickly see all orders that are either “Processing” or “On Hold” so you can take immediate action. That’s where filtering by multiple statuses comes in! This guide will show you a few straightforward ways to achieve this.

Why Filter by Multiple Order Statuses?

Think of it like this: you’re running Read more about How To Add Tracking To Woocommerce Order a bakery. You need to know which cakes are currently being baked (Processing) and which ones are ready for pickup but are on hold (On Hold). Filtering allows you to quickly isolate this specific group of orders.

Here are a few more examples of why you might want to filter by multiple statuses:

    • Inventory Management: See all orders that are “Processing” and “Completed” to understand product outflow.
    • Customer Service: Track “On Hold” and “Pending Payment” orders to proactively reach out to customers.
    • Reporting: Analyze the performance of orders in “Cancelled” and “Refunded” statuses.

    Method 1: The Built-in WooCommerce Filter (Limited)

    WooCommerce has a basic built-in filter on the Orders page (WooCommerce > Orders). You can use the “Filter by order status” dropdown. However, this *only* lets you select *one* status at a time. So, this method won’t work for our goal of multiple statuses. We’ll need to use code or a plugin.

    Method 2: Code Snippet (For the Adventurous)

    This method involves adding a small code snippet to your website. Important: Editing your theme’s `functions.php` file directly can be risky. It’s *highly recommended* to use a child theme or a plugin like “Code Snippets” for adding custom code. This prevents your changes from being overwritten when the theme updates.

    Here’s the code:

     /** 
  • Filter WooCommerce orders by multiple statuses.
  • * @param WP_Query $query
  • */ function filter_woocommerce_orders_by_multiple_statuses( $query ) { global $pagenow; global $typenow;

    // Only apply to the WooCommerce orders admin page.

    if ( ‘edit.php’ !== $pagenow || ‘shop_order’ !== $typenow ) {

    return;

    }

    // Check if our custom filter is active.

    if ( isset( $_GET[‘order_status_filter’] ) && ! empty( $_GET[‘order_status_filter’] ) ) {

    $statuses = explode( ‘,’, sanitize_text_field( $_GET[‘order_status_filter’] ) );

    $query->query_vars[‘post_status’] = $statuses;

    }

    }

    add_action( ‘pre_get_posts’, ‘filter_woocommerce_orders_by_multiple_statuses’ );

    /

    * Add a custom filter to the WooCommerce orders admin page.

    */

    function add_custom_order_status_filter() {

    global $pagenow;

    global $typenow;

    // Only apply to the WooCommerce orders admin page.

    if ( ‘edit.php’ !== $pagenow || ‘shop_order’ !== $typenow ) {

    return;

    }

    $selected_statuses = isset( $_GET[‘order_status_filter’] ) ? sanitize_text_field( $_GET[‘order_status_filter’] ) : ”;

    $order_statuses = wc_get_order_statuses(); // Get all WooCommerce order statuses

    echo ”;

    echo ” . __(‘Filter by Multiple Statuses’, ‘woocommerce’) . ”;

    foreach ( $order_statuses as $status_key => $status_name ) {

    $selected = ( strpos($selected_statuses, str_replace(‘wc-‘, ”, $status_key)) !== false ) ? ‘selected=”selected”‘ : ”;

    $status_key_without_wc = str_replace(‘wc-‘, ”, $status_key);

    echo ” . esc_html( $status_name ) . ”;

    }

    echo ”;

    submit_button( __( ‘Filter’ ), ‘secondary’, false, false );

    }

    add_action( ‘restrict_manage_posts’, ‘add_custom_order_status_filter’ );

    Explanation:

    1. `filter_woocommerce_orders_by_multiple_statuses`: This function modifies the WordPress query that fetches orders. It checks if our custom filter is active (meaning a value has been selected in the dropdown). If so, it explodes the comma-separated list of statuses into an array and sets it as the `post_status` in the query, effectively filtering the orders.

    2. `add_custom_order_status_filter`: This function adds a dropdown select box to the Orders page in your WooCommerce admin area. It fetches all available order statuses using `wc_get_order_statuses()` and creates the dropdown options.

    How to Use It:

    1. Install and activate the “Code Snippets” plugin (or create a child theme).

    2. Add a new snippet.

    3. Copy and paste the code into the snippet editor.

    4. Save and activate the snippet.

    Now, when you go to WooCommerce > Orders, you will see a new dropdown labeled “Filter by Multiple Statuses.” You can select multiple options by holding `Ctrl` (Windows) or `Command` (Mac) while clicking on the statuses you want to filter by. The values will be passed through the URL comma separated.

    Example: To filter for “Processing” and “On Hold” orders, select both in the dropdown, and the URL will look something like this: `wp-admin/edit.php?post_type=shop_order&order_status_filter=processing,on-hold&s=`

    Method 3: WooCommerce Plugins (Easiest for Non-Coders)

    If you’re not comfortable with code, the easiest option is to use a plugin. There are several plugins available in the WordPress repository that allow you to filter WooCommerce orders by multiple statuses. Some popular options include:

    • Advanced Order Export For WooCommerce (often comes with filtering features)
    • WooCommerce Order Search (might include advanced filtering)

    How to Use a Plugin (General Steps):

    1. Go to Plugins > Add New in your WordPress dashboard.

    2. Search for a plugin that offers order filtering, such as “Advanced Order Export For WooCommerce.”

    3. Install and activate the plugin.

    4. Refer to the plugin’s documentation for instructions on how to use its filtering features. Generally, you’ll find the filtering options on the WooCommerce Orders page, or within the plugin’s settings.

    Benefits of Using a Plugin:

    • User-Friendly Interface: Plugins typically provide an intuitive interface for selecting multiple statuses.
    • No Coding Required: You don’t need to write or edit any code.
    • Extra Features: Many plugins offer additional features like exporting order data, advanced search, and custom reporting.

Conclusion

Filtering WooCommerce orders by multiple statuses is a powerful way to manage your store more efficiently. While the built-in filter is limited, you can achieve this functionality either by using a custom code snippet (for those comfortable with code) or, more easily, by installing a dedicated WooCommerce plugin. Choose the method that best suits your technical skills and requirements, and start gaining better insights into your order data!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *