From de6d55eef94a66f029a2cb1514e918fbdfbc977c Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Wed, 2 Dec 2020 10:37:46 -0300 Subject: [PATCH] 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). --- includes/data-stores/class-wc-product-data-store-cpt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 9e5690853b7..24a7b128d6e 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -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 = ''; }