Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wc_get_orders() unexpected behavior with legacy orders, field_query and meta_query ignored #46076

Open
3 of 5 tasks
Sartoric opened this issue Mar 29, 2024 · 1 comment · May be fixed by #47457
Open
3 of 5 tasks

wc_get_orders() unexpected behavior with legacy orders, field_query and meta_query ignored #46076

Sartoric opened this issue Mar 29, 2024 · 1 comment · May be fixed by #47457
Assignees
Labels
focus: custom order tables / HPOS Issues related to High-Performance Order Storage (HPOS) née Custom Order Tables. focus: order Issues related to orders. priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. team: Proton type: bug The issue is a confirmed bug. type: community contribution

Comments

@Sartoric
Copy link

Prerequisites

  • I have carried out troubleshooting steps and I believe I have found a bug.
  • I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug

Using the wc_get_orders() function to retrieve orders when the "legacy" option is selected lead to potential unexpected behavior, since the *_query arguments are simply ignored/missing in the final SQL.

At least update the documentation as it's misleading

wc_get_orders and WC_Order_Query provide a standard way of retrieving orders that is safe to use and will not break due to database changes in future WooCommerce versions.

Expected behavior

Working the same way it works when using HPOS

Actual behavior

the *_query (at least meta and field) are not used and all the orders are returned.

Steps to reproduce

  • create an $args set that includes a meta_query or a field_query array to filter the orders
  • run the wc_get_orders() and check the number of orders returned

WordPress Environment

Wordpress 6.4.3
WooCommerce 8.7.0

Isolating the problem

  • I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
  • This bug happens with a default WordPress theme active, or Storefront.
  • I can reproduce this bug consistently using the steps above.
@rrennick rrennick added focus: order Issues related to orders. focus: data-store Issues related to custom tables. team: Proton labels Apr 1, 2024
@barryhughes barryhughes added the type: bug The issue is a confirmed bug. label Apr 2, 2024
@jorgeatorres jorgeatorres added the focus: custom order tables / HPOS Issues related to High-Performance Order Storage (HPOS) née Custom Order Tables. label Apr 5, 2024
@jorgeatorres
Copy link
Member

Hi @Sartoric!

Even though both field_query and meta_query are specifically documented as HPOS-only (and so not subject to backwards compatibility), we understand this can be confusing.
We've discussed on the team, and regardless of the work in #37564, we think it'd be good to indicate the use of unsupported properties via a _doing_it_wrong() and possibly returning no orders (as you've suggested).

As such, I'm bumping priority on this issue and we'll take a look soon.

@jorgeatorres jorgeatorres added priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. and removed focus: data-store Issues related to custom tables. labels Apr 5, 2024
@jorgeatorres jorgeatorres self-assigned this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: custom order tables / HPOS Issues related to High-Performance Order Storage (HPOS) née Custom Order Tables. focus: order Issues related to orders. priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. team: Proton type: bug The issue is a confirmed bug. type: community contribution
Projects
Development

Successfully merging a pull request may close this issue.

4 participants