Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets My Account Order Status

WooCommerce: Filter By Order Status @ My Account Orders

Last Revised: Jul 2024

STAY UPDATED

Here’s a great customization that all store managers should implement on their WooCommerce website!

For some reason you can refine the backend orders table if you are an admin, but logged in customers can’t filter by order status under My Account > Orders!

This is pretty bad, especially if you run a store where customers place many orders and the My Account Orders tab is full of entries. It may be helpful for customers to search all “Pending” orders for example, or maybe access al their “Completed” ones to download their files again.

So, here’s the fix – you’re welcome!

Cool, uh? Here’s a super simple filter where, on click, customers can refine by order status and get e.g. only “Pending payment” orders.

PHP Snippet: Display Order Status Filters @ WooCommerce My Account > Orders Tab

/**
 * @snippet       Status Filters @ My Account Orders - WooCommerce
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

// ------------
// 1. Let orders query listen to URL parameter

add_filter( 'woocommerce_my_account_my_orders_query', 'bbloomer_my_account_orders_filter_by_status' );

function bbloomer_my_account_orders_filter_by_status( $args ) {
	if ( isset( $_GET['status'] ) && ! empty( $_GET['status'] ) ) {
		$args['status'] = array( $_GET['status'] );
	}
	return $args;
}

// ------------
// 2. Display list of filters

add_action( 'woocommerce_before_account_orders', 'bbloomer_my_account_orders_filters' );

function bbloomer_my_account_orders_filters() {
	echo '<p>Filter by: ';
	$customer_orders = 0;
	foreach ( wc_get_order_statuses() as $slug => $name ) {
		$status_orders = count( wc_get_orders( [ 'status' => $slug, 'customer' => get_current_user_id(), 'limit' => -1 ] ) );
		if ( $status_orders > 0 ) {
			if ( isset( $_GET['status'] ) && ! empty( $_GET['status'] ) && $_GET['status'] == $slug ) { 
				echo '<b>' . $name . ' (' . $status_orders . ')</b><span class="delimit"> - </span>';
			} else echo '<a href="' . add_query_arg( 'status', $slug, wc_get_endpoint_url( 'orders' ) ) . '">' . $name . ' (' . $status_orders . ')</a><span class="delimit"> - </span>';
		}
		$customer_orders += $status_orders;
	}
	if ( isset( $_GET['status'] ) && ! empty( $_GET['status'] ) ) {
		echo '<a href="' . remove_query_arg( 'status' ) . '">All statuses (' . $customer_orders . ')</a>';
	} else echo '<b>All statuses (' . $customer_orders . ')</b>';
	echo '</p>';
}

// ------------
// 3. My Account Orders Pagination fix

add_action( 'woocommerce_before_account_orders', function() {
	add_filter( 'woocommerce_get_endpoint_url', 'bbloomer_my_account_orders_filter_by_status_pagination', 9999, 4 );
});
		   
function bbloomer_my_account_orders_filter_by_status_pagination( $url, $endpoint, $value, $permalink ) {
	if ( 'orders' == $endpoint && isset( $_GET['status'] ) && ! empty( $_GET['status'] ) ) {
		return add_query_arg( 'status', $_GET['status'], $url );
	}
	return $url;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

4 thoughts on “WooCommerce: Filter By Order Status @ My Account Orders”

  1. Dylan
    October 17, 2024

    Hello, thank you very much.
    What about the option for logged in customers to search for a specific order by searching the order number in the my-account/orders page, it is possible?

    I found no answers/ solutions or plugin for that.

    Reply
    1. Rodolfo Melogli
      October 24, 2024

      Dylan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  2. Youssef
    June 23, 2024

    Thank you for this amazing snippet! There is just a problem and I hope you can solve it.

    When someone filters their orders by status, they discover that the My Orders tab URL base has changed. Let me give you an example.

    I’ve filtered orders by status “Cancelled”, and the page URL is now: /my-account/orders/?status=wc-cancelled, but now also the URL base for the My Orders tab is: /my-account/orders /?status= wc-cancelled instead of /my-account/orders, I can’t understand what’s causing this problem.

    Reply
    1. Rodolfo Melogli
      July 11, 2024

      Very good point, I’ve now added an edit to part #3, let me know if it works!

      Reply
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

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


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: How to Configure Product and Order Sync
  • WooCommerce: “Beautify” Item Meta in Order Emails
  • WooCommerce: Per-Product Checkout Fees / Tariffs
  • WooCommerce: Auto-Cancel Orders After 3 Failed Payments
  • WooCommerce: Bulk Delete Pending / Failed Scheduled Actions

Latest Comments

  1. Tiago Sartor on WooCommerce: Access Thank You Page from Order Admin
  2. Piotr on WooCommerce: Replace Variable Price With Active Variation Price
  3. Rodolfo Melogli on WooCommerce: Redirect Empty Paginated Category Pages (404)

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x