Skip to content

Commit

Permalink
Merge pull request #2666 from 10up/fix/wc-search-by-order-id
Browse files Browse the repository at this point in the history
WC Orders: properly add ID to fields when searching for digits
  • Loading branch information
felipeelia authored Mar 22, 2022
2 parents 93b2e70 + 2d0b6c2 commit 0c040f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public function translate_args( $query ) {
// Search query
if ( 'shop_order' === $post_type ) {
$default_search_fields = array( 'post_title', 'post_content', 'post_excerpt' );
if ( is_int( $s ) ) {
if ( ctype_digit( $s ) ) {
$default_search_fields[] = 'ID';
}
$search_fields = $query->get( 'search_fields', $default_search_fields );
Expand Down
4 changes: 2 additions & 2 deletions tests/php/features/TestWooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function testSearchShopOrderById() {
ElasticPress\Elasticsearch::factory()->refresh_indices();

$args = array(
's' => $shop_order_id,
's' => (string) $shop_order_id,
'post_type' => 'shop_order',
);

Expand Down Expand Up @@ -215,7 +215,7 @@ public function testSearchShopOrderByMetaFieldAndId() {
ElasticPress\Elasticsearch::factory()->refresh_indices();

$args = array(
's' => $shop_order_id_1,
's' => (string) $shop_order_id_1,
'post_type' => 'shop_order',
);

Expand Down

0 comments on commit 0c040f0

Please sign in to comment.