-
Notifications
You must be signed in to change notification settings - Fork 798
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
Jetpack Sync HPOS: Ensure get_objects_by_id will return all relevant orders #38251
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
} | ||
$orders = wc_get_orders( | ||
|
||
$orders = wc_get_orders( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vedanshujain Added you as a reviewer mostly to confirm this is the recommended way to ensure we fetch all the orders, including the ones with trash
and auto-draft
statuses via wc_get_orders
protected function get_all_possible_order_status_keys() { | ||
$order_statuses = array( 'checkout-draft', 'auto-draft', 'trash' ); | ||
$wc_order_statuses = array(); | ||
if ( function_exists( 'wc_get_order_statuses' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is wc_get_order_statuses
not available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When WooCommerce is not active I guess, but since it's an external function I think it's safer to check if it exists first before attempting to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code makes sense and tests as expected. 🚢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes a bug in
WooCommerce_HPOS_Orders
'sget_objects_by_id
method when querying orders viawc_get_orders
.We used to specify the order ids we need using
include
query argument, however this resulted in the later getting ignored and returning all orders instead.This is fixed by replacing
include
withpost__in
as per the corresponding WP_Query docs thatwc_get_orders
uses under the hood.Proposed changes:
Automattic\Jetpack\Sync\Modules\WooCommerce_HPOS_Orders
: Add alimit
argument set to-1
to ensure all requested orders will be returned when fetching orders viawc_get_orders
used inget_objects_by_id
method.Automattic\Jetpack\Sync\Modules\WooCommerce_HPOS_Orders
: Introduceget_all_possible_order_status_keys
for fetching all the possible order statuses and use it inget_objects_by_id
when fetching orders viawc_get_orders
. This is needed because by defaultwc_get_orders
will ignoredraft
andtrash
statuses since it usesWP_Query
under the hood and WP_Query retrieves any status except forinherit
,trash
andauto-draft
. Custom post statuses withexclude_from_search
set totrue
are also excluded.Other information:
Jetpack product discussion
p9dueE-8ec-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Pre-requisites:
A JP connected site with WooCommerce and Jetpack plugins active.
At least 11 orders with all the possible statuses (see
get_all_possible_order_status_keys
)Enter
wp shell
auto-draft
andtrash
statuses will be missingexclude_from_search
set totrue
and ensuring the corresponding order will be returned too.