woocommerce_orders_table_query_status_union_optimization
Filters whether a query for multiple order statuses ordered by creation date may be rewritten as a UNION ALL of single-status queries for performance. The rewrite produces the same results and, even when enabled here, only applies to queries generated purely from the 'type' and 'status' query args (no search, meta or field filters), such as the default order admin list screen query.
Hosts that know their database benefits from the rewrite regardless of store size (or that don't want to depend on the order count cache being warm) can force-enable it with add_filter( woocommerce_orders_table_query_status_union_optimization, '__return_true' ); the structural eligibility checks above still apply.
Usage
add_filter( 'woocommerce_orders_table_query_status_union_optimization', 'wp_kama_woocommerce_orders_table_query_status_union_optimization_filter', 10, 2 );
/**
* Function for `woocommerce_orders_table_query_status_union_optimization` filter-hook.
*
* @param bool $enabled Whether the rewrite is enabled.500,000; FALSE otherwise (including when the order count cache is cold).
* @param OrdersTableQuery $query The OrdersTableQuery instance.
*
* @return bool
*/
function wp_kama_woocommerce_orders_table_query_status_union_optimization_filter( $enabled, $query ){
// filter...
return $enabled;
}
- $enabled(true|false)
- Whether the rewrite is enabled.500,000; FALSE otherwise (including when the order count cache is cold).
Default: TRUE only when the cached number of orders matching the queried types and statuses is at least - $query(OrdersTableQuery)
- The OrdersTableQuery instance.
Changelog
| Since 11.0.0 | Introduced. |
Where the hook is called
woocommerce_orders_table_query_status_union_optimization
woocommerce/src/Internal/DataStores/Orders/OrdersTableStatusUnionQuery.php 298
return (bool) apply_filters( 'woocommerce_orders_table_query_status_union_optimization', $enabled, $this->query );