fix(woocommerce): do not integrate queries for product variations - #4350
Open
faisalahammad wants to merge 1 commit into
Open
fix(woocommerce): do not integrate queries for product variations#4350faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
product_variation was part of the default supported post types for the WooCommerce feature. Queries containing product_variation, like the ones built by third party plugins such as WooCommerce Single Variations, were then served by Elasticsearch. The posts_pre_query filter skips the SQL hooks those plugins rely on, breaking them. Remove product_variation from the default supported post types. Queries that include it now run against MySQL and keep the normal query hooks. Sites that want ElasticPress to handle product variation queries can still opt in through the ep_woocommerce_products_supported_post_types filter. Fixes 10up#3887
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The WooCommerce feature listed
product_variationas a default supported post type. Third party plugins such as WooCommerce Single Variations addproduct_variationto the post type on frontend queries. Those queries were then served by Elasticsearch, and theposts_pre_queryfilter skipped the SQL hooks those plugins rely on, which broke them.This change removes
product_variationfrom the default supported post types. Queries that include it now run against MySQL and keep the normal query hooks. Sites that want ElasticPress to handle product variation queries can still opt in through theep_woocommerce_products_supported_post_typesfilter.Fixes #3887
Changes
includes/classes/Feature/WooCommerce/Products.php
Before:
After:
$post_types = [];Why:
product_variationis never queried as a post type by any core WooCommerce frontend flow. Keeping it in the default list made every query that contains it (often added by third party plugins) integrate with Elasticsearch and skip the normal query hooks.tests/php/features/WooCommerce/TestWooCommerceProduct.php
testGetSupportedPostTypesupdated:product_variationis no longer part of the default supported post types, andproductis returned whenep_integrateis explicitly true.testProductVariationQueryDoesNotIntegrate: a query withpost_type = ['product', 'product_variation']andep_integrate = truemust not trigger ElasticPress integration.Testing
Test 1: Regression test
composer test -- --filter='testGetSupportedPostTypes|testProductVariationQueryDoesNotIntegrate'Test 2: Full WooCommerce product suite
composer test -- --filter='TestWooCommerceProduct'testPriceFilterWithTax) is unrelated and reproduces on a clean develop branch.Test 3: Manual