Trigger doing_it_wrong for CPT order queries with HPOS query args #47457
+26
−0
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.
Submission Review Guidelines:
Changes proposed in this Pull Request:
With HPOS we introduced a few new capabilities in order querying. In particular, when HPOS is the backing datastore for orders, you can create complex queries using
meta_query
andfield_query
.We have explored adding a compat layer that would allow some of those queries to work with the CPT datastore, but due to the differences in the underlying db structure this is not always possible, and might not be worth the effort given we want to push HPOS over CPT.
This PR introduces a "doing it wrong" warning when either
meta_query
orfield_query
are being used in an order query and the datastore is the CPT one. Currently, those special arguments are silently ignored, producing a result set that can be confusing.meta_query
to the CPT datastore, and yet we would be triggering a warning. Not sure how likely that is and the code does limit the warning to instances of the default CPT datastore (so if extended, it won't trigger any warnings), but I guess it could still happen. Could this be a problem?Closes #46076.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Make sure WordPress posts storage is selected in WC > Settings > Advanced > Features > Order data storage.
If necessary, run
wp hpos sync
to sync so that the option becomes available.Open a CLI shell (
wp shell
) and confirm that you get this "doing it wrong" notice...... when running any of the following commands:
Drop the following snippet somewhere suitable (like wp-content/mu-plugins/) to "simulate" the default CPT order datastore not being used but extended in 3rd party code:
Confirm that no notice is triggered when you run the commands from step 2.
Remove the PHP snippet from step 3.
Change the order data storage back to HPOS in WC > Settings > Advanced > Features.
Confirm that no notice is triggered when you run the commands from step 2.
Changelog entry
Significance
Type
Message
Comment