Filtering your WooCommerce orders gives you a way to find the transaction records you’re looking for faster. When we’re working on threads in the help desk, this is useful to us as developers as well so we can find the orders relevant to the issue quickly.

One of the most helpful filters for debugging is to filter orders by payment method used, as we’ll use this for payment gateway support, or when seeing if an issue occurs with one type of gateway (like an off-site gateway) but not another. Since we recently built a helper plugin to do just that, I’ll go over a couple useful plugins for filtering your WooCommerce orders today.

Filter WooCommerce Orders by Payment Method

For the merchants in the crowd, you can download the code above as a plugin by clicking “Download .zip” in the top-right, then installing it into your store just like any other plugin. For the developers, we’ll go a bit more in-depth as to what this is doing shortly.

When using this plugin, you’ll see that a new filter is added to your orders list, letting you choose which payment methods to show:

WooCommerce Order Filter by Payment method

If you select one to filter your orders, you’ll see that only orders placed with that payment gateway will be shown rather than the complete order list.

WooCommerce Orders Filtered by Payment

That’s all there is to it! You can now see only PayPal orders, only credit card orders, or even better, if you perhaps allow cash on delivery or another non-standard / paid “up front” method, you can check for these orders easily!

Behind the scenes

For the developers, let’s have a look at what this plugin is actually doing. You’ll notice it uses 2 hooks:

  • restrict_manage_posts — lets us insert content before the “Filter” button in any posts lists. Since we only want to filter orders, notice that the callback hooked in here uses the global $typenow to check for the right post type list, then it outputs my selector.
  • request — lets us adjust query variables to adjust returned results. In our case, since payment method is stored as post meta, we’ll add a couple WP_Query custom parameters for the payment method meta key and the value we’re filtering for.

When we combine these two hooks, we can (1) add the selector for the filter, and (2) when “Filter” is clicked, get the URL parameter from our selector to adjust the orders query using our filter.

This could prove really useful if you have your own custom meta keys for which you’d like to be able to filter orders, such as delivery date, fulfillment provider, or other data.

Filter WooCommerce Orders by Coupon

Now let’s take a slightly more complex example from a developer perspective, but still a useful tool for merchants. We can filter orders by the coupon used, which can be nice for checking orders from a promotion or if a coupon requires further action from the merchant.

You can download and install this plugin by clicking “Clone or Download”, then “Download ZIP” to get a plugin file you can install. When added to your site, this will add a new filter listing all published coupons in your store. You can then choose which coupon you’d like to filter for, and your orders list will adjust accordingly.

WooCommerce Filter Orders by Coupons used

Behind the scenes

This sort of query is more complicated to adjust because coupon usage is not stored on the order object itself, which is what we’re filter for. Instead, it’s stored as an order item. Since order item data is stored in a separate database table, we’ll need to use SQL to JOIN these tables to filter a query like this.

As a result, you’ll see that we don’t use the request hook here, but rather substitute 2 different hooks instead:

  • posts_join — lets us join another table onto the posts query. We’ll use this to check the typenow, and join the order items table to the orders table if filtering orders (and of course, ensure our filter is actually being used so we don’t do this unnecessarily).
  • posts_where — this is what basically takes the place of the request hook now, letting us directly modify the SQL query to add a WHERE condition, checking for the data we’ve added in our previous JOIN.

Since fees, products, shipping methods, and coupons are all stored as order line items, this sort of filtering could let you filter by shipping method selected, whether a particular fee was chosen or not (e.g., getting all orders that opted for expedited handling or shipping insurance), and more.


In either case, this scratches the surface of what you can do to filter WooCommerce orders in your shop admin, helping merchants find the specific orders they need, or pointing developers towards what they’d need to modify to get their own filtered order lists.

Published by Beka Rice

Beka manages WooCommerce product direction for SkyVerge, such as plugin roadmaps, documentation, and sales copy. She typically gets stuck with boring administrative tasks, but likes to write so she has an excuse to spend more time jamming out to anything from The Clash to Lady Gaga.

4 Comments

  1. I’d like to filter by shipping method, is there anything available for this?

    Reply
    • Hey Ruth, I don’t know of a plugin that’s available for this unfortunately. It would require something more complex like the second example here, as shipping methods are stored as line items rather than just as data on the order (since there can be more than one per order).

      Reply
  2. Great plugin Beka! Question: How can i filter orders based on custom field create in order page? For instance if i have created “Shipping Status” custom field in order page. I want to filter orders by shipping status. How can i do that?

    Reply
    • Hey Deven, afraid this isn’t something I have code handy for, but it would be similar to the first example here — payment method is order meta, the same way as custom fields, so you’d need to add this meta to the query. If this isn’t something you’d done before, Codeable is great for these sort of projects.

      Reply

Leave a Reply

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

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match