Removed the lowercase conversion of product search terms
When searched in a case sensitive manner, the conversion to lowercase causes uppercase matches that would have been found to be lost. This change increases the tolerance of the OR search format while also removing this unintended side-effect.
This commit is contained in:
parent
93e3e5bfe1
commit
874be93c14
|
@ -880,7 +880,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
}
|
||||
|
||||
return $wpdb->get_results(
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"
|
||||
SELECT posts.ID as id, posts.post_parent as parent_id
|
||||
FROM {$wpdb->posts} AS posts
|
||||
|
@ -898,7 +898,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
)
|
||||
GROUP BY posts.ID
|
||||
"
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1553,7 +1553,6 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
$type_where = '';
|
||||
$status_where = '';
|
||||
$limit_query = '';
|
||||
$term = wc_strtolower( $term );
|
||||
|
||||
/**
|
||||
* Hook woocommerce_search_products_post_statuses.
|
||||
|
@ -1567,8 +1566,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
);
|
||||
|
||||
// See if search term contains OR keywords.
|
||||
if ( strstr( $term, ' or ' ) ) {
|
||||
$term_groups = explode( ' or ', $term );
|
||||
if ( stristr( $term, ' or ' ) ) {
|
||||
$term_groups = preg_split( '/\s+or\s+/i', $term );
|
||||
} else {
|
||||
$term_groups = array( $term );
|
||||
}
|
||||
|
|
|
@ -797,6 +797,12 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$this->assertContains( $product3->get_id(), $results );
|
||||
$this->assertContains( $product4->get_id(), $results );
|
||||
|
||||
$results = $data_store->search_products( 'blue-widget-1 OR green-widget', '', true, true );
|
||||
$this->assertContains( $product->get_id(), $results );
|
||||
$this->assertNotContains( $product2->get_id(), $results );
|
||||
$this->assertContains( $product3->get_id(), $results );
|
||||
$this->assertContains( $product4->get_id(), $results );
|
||||
|
||||
$results = $data_store->search_products( '"green widget"', '', true, true );
|
||||
$this->assertNotContains( $product->get_id(), $results );
|
||||
$this->assertNotContains( $product2->get_id(), $results );
|
||||
|
|
Loading…
Reference in New Issue