Skip to content

Commit 2668bf6

Browse files
authored
Merge pull request woocommerce#25314 from woocommerce/fix/24746
Removed the lowercase conversion of product search terms
2 parents 289c932 + 874be93 commit 2668bf6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

includes/data-stores/class-wc-product-data-store-cpt.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ public function get_on_sale_products() {
880880
}
881881

882882
return $wpdb->get_results(
883-
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
883+
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
884884
"
885885
SELECT posts.ID as id, posts.post_parent as parent_id
886886
FROM {$wpdb->posts} AS posts
@@ -898,7 +898,7 @@ public function get_on_sale_products() {
898898
)
899899
GROUP BY posts.ID
900900
"
901-
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
901+
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
902902
);
903903
}
904904

@@ -1553,7 +1553,6 @@ public function search_products( $term, $type = '', $include_variations = false,
15531553
$type_where = '';
15541554
$status_where = '';
15551555
$limit_query = '';
1556-
$term = wc_strtolower( $term );
15571556

15581557
/**
15591558
* Hook woocommerce_search_products_post_statuses.
@@ -1567,8 +1566,8 @@ public function search_products( $term, $type = '', $include_variations = false,
15671566
);
15681567

15691568
// See if search term contains OR keywords.
1570-
if ( strstr( $term, ' or ' ) ) {
1571-
$term_groups = explode( ' or ', $term );
1569+
if ( stristr( $term, ' or ' ) ) {
1570+
$term_groups = preg_split( '/\s+or\s+/i', $term );
15721571
} else {
15731572
$term_groups = array( $term );
15741573
}

tests/unit-tests/product/data-store.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,12 @@ public function test_search_products() {
797797
$this->assertContains( $product3->get_id(), $results );
798798
$this->assertContains( $product4->get_id(), $results );
799799

800+
$results = $data_store->search_products( 'blue-widget-1 OR green-widget', '', true, true );
801+
$this->assertContains( $product->get_id(), $results );
802+
$this->assertNotContains( $product2->get_id(), $results );
803+
$this->assertContains( $product3->get_id(), $results );
804+
$this->assertContains( $product4->get_id(), $results );
805+
800806
$results = $data_store->search_products( '"green widget"', '', true, true );
801807
$this->assertNotContains( $product->get_id(), $results );
802808
$this->assertNotContains( $product2->get_id(), $results );

0 commit comments

Comments
 (0)