Override the default MySQL query limit when counting orders #13
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.
OrderLimiter::count_qualifying_orders()
relies onwc_get_orders()
, which is several layers of abstraction overWP_Query
.Currently, if we analyze the query, it looks something like this:
Unfortunately, that last line is the problem: we're limiting the qualifying orders to 10, which is the default LIMIT value for
WP_Query
.This PR overrides that default, setting it to either the limit set by the store or
1000
(whichever is higher); this ensures that we're not running a-1
limit on a store that could potentially have a very large threshold for orders (e.g. "oh, we only want to accept 1M orders/week").Eventually, it may be worth rewriting this function to use an explicit SQL
COUNT(*)
query (thus eliminating limit concerns), but we want to ensure we do that in a way that maintains compatibility with WooCommerce's CRUD APIs.This should also resolve the two open support tickets on WordPress.org: