woocommerce icon indicating copy to clipboard operation
woocommerce copied to clipboard

Trigger doint_it_wrong for CPT order queries with HPOS query args

Open jorgeatorres opened this issue 1 year ago • 1 comments

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #46076.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

Changelog entry

  • [ ] Automatically create a changelog entry from the details below.

Significance

  • [ ] Patch
  • [ ] Minor
  • [ ] Major

Type

  • [ ] Fix - Fixes an existing bug
  • [ ] Add - Adds functionality
  • [ ] Update - Update existing functionality
  • [ ] Dev - Development related task
  • [ ] Tweak - A minor adjustment to the codebase
  • [ ] Performance - Address performance issues
  • [ ] Enhancement - Improvement to existing functionality

Message

Comment

jorgeatorres avatar May 14 '24 09:05 jorgeatorres

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

github-actions[bot] avatar May 14 '24 09:05 github-actions[bot]

Hi @naman03malhotra,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like: https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

github-actions[bot] avatar May 29 '24 21:05 github-actions[bot]

Hi @naman03malhotra,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like: https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

github-actions[bot] avatar May 29 '24 21:05 github-actions[bot]

@naman03malhotra: You're right. WP-CLI is a different environment than the web one, so the error reporting needs to be explicitly set or it'd just use the defaults (which I guess on your machine are not to display certain warnings). You should still have been able to confirm those messages in your error log file, but an alternative way to enable error reporting is to execute the following (in the wp shell) before anything else:

error_reporting( E_ALL );
ini_set( 'display_errors', true );
[...]

Please let me know if the above works and I'll update the testing instructions accordingly.

jorgeatorres avatar Jul 08 '24 20:07 jorgeatorres

Hey @naman03malhotra! I've implemented Corey's suggestion which should help with 3rd party code in case it (somehow) adds support for the HPOS-only query vars to CPT. I've reworked the testing instructions to take this into account. Please let me know what you think!

jorgeatorres avatar Jul 11 '24 19:07 jorgeatorres

@naman03malhotra: I can't reproduce and can't think of reasons for such error, but I've updated the snippet with a less 'clever' version to see if that helps. Please let me know if it works for you.

jorgeatorres avatar Jul 12 '24 13:07 jorgeatorres

For now what is the correct way to get the orders based on the custom meta value? My args passed to wc_get_orders($args) are:

Array
(
    [paginate] => 1
    [limit] => 25
    [paged] => 1
    [meta_query] => Array
        (
            [relation] => AND
            [0] => Array
                (
                    [key] => _omnivalt_method
                    [value] => Array
                        (
                            [0] => omnivalt
                            [1] => omnivalt_pt
                            [2] => omnivalt_c
                            [3] => omnivalt_cp
                            [4] => omnivalt_pc
                            [5] => omnivalt_pn
                            [6] => omnivalt_ps
                        )
                    [compare] => IN
                )
        )
)

Since version WC 9.2.0 I just get the error "Order query argument (meta_query) is not supported on the current order datastore" and see empty page.

markakk avatar Sep 25 '24 12:09 markakk

@markakk the meta_query arg already didn't work with the "legacy" WordPress posts storage option for orders (now it just gives you a notice about it). If you go to WooCommerce > Settings > Advanced > Features and enable "High-performance order storage", you should be able to use meta_query.

coreymckrill avatar Oct 02 '24 21:10 coreymckrill