Use single quotes inside MySQL query to avoid issues with ANSI_QUOTES

This commit replaces double quotes with single quotes inside a MySQL query to avoid a syntax error when the SQL mode ANSI_QUOTES is enabled in MySQL. When this mode is enabled, MySQL treats double quotes as identifiers (like the backtick character) instead of as string delimiters. Before this change, sites running with this mode enabled wouldn't be able to add products to orders created manually in the admin as the modified query would fail (other places that also use product search including variations would fail as well). The commit that introduced this issue shipped in WC 4.5.0 (see https://github.com/woocommerce/woocommerce/pull/27171).
This commit is contained in:
Rodrigo Primo 2020-12-02 10:37:46 -03:00
parent f698fbdeee
commit de6d55eef9
1 changed files with 1 additions and 1 deletions

View File

@ -1614,7 +1614,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
// Variations should also search the parent's meta table for fallback fields.
if ( $include_variations ) {
$variation_query = $wpdb->prepare( ' OR ( wc_product_meta_lookup.sku = "" AND parent_wc_product_meta_lookup.sku LIKE %s ) ', $like );
$variation_query = $wpdb->prepare( " OR ( wc_product_meta_lookup.sku = '' AND parent_wc_product_meta_lookup.sku LIKE %s ) ", $like );
} else {
$variation_query = '';
}