Fixed WooCommerce data privacy eraser query deletes all orders. #2975
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.
Description of the Change
Scope
Context/Requirements
Problem
/wp-admin/erase-personal-data.php
, all orders (Cause
WooCommerce sets WC_Order_Query filters on
'customer'
inhttps://github.com/woocommerce/woocommerce/blob/9e9b4ef844ef015388c21a401aba7bdee11a0d72/plugins/woocommerce/includes/class-wc-privacy-erasers.php#L125-L133
The WooCommerce order data store expands the
'customer'
parameter inhttps://github.com/woocommerce/woocommerce/blob/9e9b4ef844ef015388c21a401aba7bdee11a0d72/plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php#L453-L466
into a meta query, resulting in the following meta query:
☝️ Note that WooCommerce is using named keys (
customer_emails
andcustomer_ids
) for the conditions and not indexed keys.The meta query processing in Indexable only expects indexed keys, and there is no following handling of other array keys:
ElasticPress/includes/classes/Indexable.php
Line 1041 in c51729e
so the meta query parameters are ignored altogether – resulting in the following, unfiltered ES statement querying all orders:
All orders are getting anonymized.
Proposed solution
Notes
How to test the Change
Changelog Entry
Fixed WooCommerce data privacy eraser query deletes all orders if ElasticPress is enabled for admin and Ajax requests.
Credits
GitHub
Props @sun, @bogdanarizancu
WordPress.org
Props tha_sun, bogdanarizancu
Checklist: