Você está visualizando atualmente WooCommerce: Filter By Order Status @ My Account Orders

WooCommerce: Filter By Order Status @ My Account Orders

  • Autor do post:
  • Categoria do post:Woocommerce
  • Tempo de leitura:5 minutos de leitura

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 Get CustomizeWoo.com FREE * @author Rodolfo Melogli * @compatible WooCommerce 8 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ // ———— // 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 ‘

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 ‘‘ . $name . ‘ (‘ . $status_orders . ‘)‘; } else echo ‘‘ . $name . ‘ (‘ . $status_orders . ‘)‘; } $customer_orders += $status_orders; } if ( isset( $_GET[‘status’] ) && ! empty( $_GET[‘status’] ) ) { echo ‘All statuses (‘ . $customer_orders . ‘)‘; } else echo ‘All statuses (‘ . $customer_orders . ‘)‘; echo ‘

‘; } // ———— // 3. My Account Orders Pagination fix 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: Add New Tab @ My Account Page
    One of the features of Bloomer Armada is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an extra “tab” to the My Account page, and how to add content inside it? Here’s the code I used (thanks to Mike Jolley for inspiration) – feel free to leave a […]
  • 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 know, the WooCommerce My Account page, which contains the Login Username or email address * Password * Remember me Log in Lost your password? shortcode, has both Login and Registration forms when […]
  • 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 is: what changes do we need to make on our WooCommerce website to become compliant? And another important query might be: how does GDPR affect non-European WooCommerce websites? In this […]
  • 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 Name to the Registration Form on the WooCommerce My Account page. By default, the WooCommerce customer Registration Form only displays the email, username, and password fields (unless username and password […]
  • 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 are multiple pages such as the My Account as logged in user, My Account as logged out, etc). This visual guide belongs to my “Visual Hook Guide Series“, that I’ve […]

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