From b7c5519b419ee77f8e20f09c5758b2b6caa588d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Soriano?= Date: Fri, 2 Dec 2022 09:54:38 +0100 Subject: [PATCH] Fix product attributes lookup data and filter by attribute widget with non-ASCII named attributes (#34432) This only fixes the classic widget, not the equivalent block. --- ...fix-product-attributes-lookup-with-non-ascii-attributes | 4 ++++ .../src/Internal/ProductAttributesLookup/Filterer.php | 7 ++++--- .../Internal/ProductAttributesLookup/LookupDataStore.php | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-product-attributes-lookup-with-non-ascii-attributes diff --git a/plugins/woocommerce/changelog/fix-product-attributes-lookup-with-non-ascii-attributes b/plugins/woocommerce/changelog/fix-product-attributes-lookup-with-non-ascii-attributes new file mode 100644 index 00000000000..ecf3682dd9d --- /dev/null +++ b/plugins/woocommerce/changelog/fix-product-attributes-lookup-with-non-ascii-attributes @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix handling of non-ASCII product attributes when the attributes lookup table is in use diff --git a/plugins/woocommerce/src/Internal/ProductAttributesLookup/Filterer.php b/plugins/woocommerce/src/Internal/ProductAttributesLookup/Filterer.php index 6d16d9061fe..f7282750c68 100644 --- a/plugins/woocommerce/src/Internal/ProductAttributesLookup/Filterer.php +++ b/plugins/woocommerce/src/Internal/ProductAttributesLookup/Filterer.php @@ -212,12 +212,13 @@ class Filterer { {$tax_query_sql['join']} {$meta_query_sql['join']} INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$this->lookup_table_name}.product_or_parent_id"; - $term_ids_sql = $this->get_term_ids_sql( $term_ids ); - $query['where'] = " + $encoded_taxonomy = sanitize_title( $taxonomy ); + $term_ids_sql = $this->get_term_ids_sql( $term_ids ); + $query['where'] = " WHERE {$wpdb->posts}.post_type IN ( 'product' ) AND {$wpdb->posts}.post_status = 'publish' {$tax_query_sql['where']} {$meta_query_sql['where']} - AND {$this->lookup_table_name}.taxonomy='{$taxonomy}' + AND {$this->lookup_table_name}.taxonomy='{$encoded_taxonomy}' AND {$this->lookup_table_name}.term_id IN $term_ids_sql {$in_stock_clause}"; diff --git a/plugins/woocommerce/src/Internal/ProductAttributesLookup/LookupDataStore.php b/plugins/woocommerce/src/Internal/ProductAttributesLookup/LookupDataStore.php index c561d1e9b00..75f91bec82c 100644 --- a/plugins/woocommerce/src/Internal/ProductAttributesLookup/LookupDataStore.php +++ b/plugins/woocommerce/src/Internal/ProductAttributesLookup/LookupDataStore.php @@ -433,7 +433,7 @@ class LookupDataStore { $terms = WC()->call_function( 'get_terms', array( - 'taxonomy' => $taxonomy, + 'taxonomy' => wc_sanitize_taxonomy_name( $taxonomy ), 'hide_empty' => false, 'fields' => 'id=>slug', )