WooCommerce: Search Orders By 2-Letter Country Code [HPOS]

WooCommerce’s order search function is essential for store admins, but with the introduction of High-Performance Order Storage (HPOS), searching by billing or shipping country code may no longer work as expected.

If you’re used to quickly filtering orders by country, this limitation can be frustrating. Fortunately, there’s a simple way to bring back this functionality using a custom code snippet.

In this post, we’ll walk through how to modify the WooCommerce order search to support two-letter country codes, making it easier to find the orders you need. Let’s dive into the solution!

Continue reading WooCommerce: Search Orders By 2-Letter Country Code [HPOS]

WooCommerce: Get List of Users Who Purchased a Product ID

This time around we’ll take a look at some SQL. As you know, WooCommerce orders (same as WooCommerce products) are stored in the WordPress database.

Instead of using complex PHP loops and conditionals, sometimes knowing a bit of database “reading” can help. I took some inspiration (because I don’t know everything by heart) from the wc_customer_bought_product() WooCommerce function, which contains some SQL to check if a user has purchased a given product.

I’ve played a little with the same SQL SELECT call, and managed to return the list of user email addresses who have purchased a specific product ID. If you’re ever going to need this, enjoy!

Continue reading WooCommerce: Get List of Users Who Purchased a Product ID