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!

PHP Snippet: Enable Order Search by 2-Letter Country Code @ WordPress Admin [HPOS]
This code consists of two main parts.
The first part adds a custom filter to WooCommerce’s High-Performance Order Storage (HPOS) search options, allowing an admin to filter orders by a two-letter country code.
The second part hooks into the query generation to modify the WHERE clause, enabling the search to match the entered country code with the country stored in the order addresses. Specifically, it checks if the search filter is set to “country” and, if so, adjusts the query to search for orders where the billing or shipping address matches the provided two-letter country code. This is achieved by joining the orders table with the order addresses table and filtering on the country field.
/**
* @snippet Search Orders By Country Code
* @tutorial https://businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_hpos_admin_search_filters', function( $options ) {
$options['country'] = '2-Letter Country Code';
return $options;
});
add_filter( 'woocommerce_hpos_generate_where_for_search_filter', 'filter_orders_by_country', 10, 4 );
function filter_orders_by_country( $where, $search_term, $search_filter, $query ) {
global $wpdb;
if ( 'country' === $search_filter ) {
$orders = $wpdb->prepare( "{$wpdb->prefix}wc_orders.id IN ( SELECT order_id FROM {$wpdb->prefix}wc_order_addresses WHERE country = %s )", $search_term );
return $orders;
}
return $where;
}
And here’s a screenshot showing the results when searching for “IT”:
