Working with WooCommerce, sometimes there are small tweaks that can enhance our experience, making administrative tasks simpler. One such enhancement I’ve recently explored is adding an email filter directly within the Orders page of WooCommerce. This is especially useful if you want to quickly hide all orders associated with a specific email.
Before implementing any code changes, always ensure your site is backed up. This will help you restore things in case of unforeseen errors. I recommend using Jetpack Backup for real-time backups and one-click restores.
What We Are Doing to Do
We will add a text input to the WooCommerce Orders page where you can type in an email address, or multiple ones separated by comma. Once submitted, the page will filter and hide any orders from that specific email.
A Little Bit of Code
First, we introduce the email input on the Orders page. This is achieved by the add_email_filter
function, which checks if we’re on the shop_order
page and then displays the email input field:
Next, once an email is provided, the system needs to fetch the relevant orders. This is where filter_orders_by_emails
comes in. It listens for the email input, splits it into multiple emails if it’s separated by comma, and retrieves all orders that DO NOT include those email addresses:
Hide Orders From Pre-Defined Email Addresses
If your goal is instead to hide orders from a pre-defined email address, the code is slightly different, but as simple as the one above. This could be useful if you have, for example, a Point of Sale connected to WooCommerce that would generate lots of orders on the website:
Conclusion
Simple, yet effective! By integrating this into your WooCommerce setup, you’ll be able to seamlessly filter orders by email for registered and unregistered customers, streamlining your administrative tasks. As always, if you have any questions or encounter issues, feel free to share in the comments. Happy WooCommerce-ing!
Leave a Reply