Commit 5194650f4c0 for woocommerce
commit 5194650f4c05c018baecc1c6477fb4d898d59f68
Author: Faisal Ahammad <faisalahammad24@gmail.com>
Date: Fri Jul 3 20:50:26 2026 +0600
fix: use post-filter query args for no_found_rows gate in ListTable (#66207)
The cache fast-path gate in ListTable::prepare_items() inspected
->order_query_args (pre-filter) to decide whether to skip the
COUNT query. When a filter added extra keys like meta_query via
woocommerce_order_list_table_prepare_items_query_args, the check
was blind to those keys and still set no_found_rows=true, producing
incorrect cached total counts.
Changed the gate to inspect (post-filter) so any
key added by a filter correctly disables the cache fast path.
Fixes #66160
diff --git a/plugins/woocommerce/changelog/fix-66160-list-table-prepare-items-cache-gate b/plugins/woocommerce/changelog/fix-66160-list-table-prepare-items-cache-gate
new file mode 100644
index 00000000000..ec9f6aeabc7
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-66160-list-table-prepare-items-cache-gate
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fixed incorrect order counts when custom query_args are added via the order list table prepare_items query args filter.
diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php
index b3daab966a4..c8c6cb4370d 100644
--- a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php
+++ b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php
@@ -436,7 +436,7 @@ class ListTable extends WP_List_Table {
$order_query_args['paginate'] = true;
// Attempt to use cache if no additional query arguments are used.
- if ( empty( array_diff( array_keys( $this->order_query_args ), array( 'limit', 'page', 'paginate', 'type', 'status', 'orderby', 'order' ) ) ) ) {
+ if ( empty( array_diff( array_keys( $order_query_args ), array( 'limit', 'page', 'paginate', 'type', 'status', 'orderby', 'order' ) ) ) ) {
$this->order_query_args['no_found_rows'] = true;
$order_query_args['no_found_rows'] = true;
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
index 7f1e1cd7538..b8516a068ab 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
@@ -283,4 +283,44 @@ class ListTableTest extends \WC_Unit_Test_Case {
$this->assertSame( 'order_id', $query_args['search_filter'] ?? null, 'The selected search filter should be applied' );
$this->assertArrayNotHasKey( 'no_found_rows', $query_args, 'Searches should count their actual results' );
}
+
+ /**
+ * @testdox When a filter modifies the query args via woocommerce_order_list_table_prepare_items_query_args, the cache fast path is not used.
+ */
+ public function test_filter_modifying_query_args_disables_no_found_rows(): void {
+ \WC_Helper_Order::create_order();
+
+ $called = false;
+
+ $callback = function ( $args ) use ( &$called ) {
+ $called = true;
+ $args['meta_query'][] = array(
+ 'key' => 'my_custom_meta_key',
+ 'value' => 'any_value',
+ 'compare' => '=',
+ );
+ return $args;
+ };
+ add_filter( 'woocommerce_order_list_table_prepare_items_query_args', $callback );
+
+ $this->sut->prepare_items();
+ $query_args = $this->get_order_query_args();
+
+ remove_filter( 'woocommerce_order_list_table_prepare_items_query_args', $callback );
+
+ $this->assertTrue( $called, 'The filter should have been invoked' );
+ $this->assertArrayNotHasKey( 'no_found_rows', $query_args, 'When a filter modifies the query args, the cache fast path should not be used' );
+ }
+
+ /**
+ * @testdox Without any filter modifying the query args, the cache fast path is still used.
+ */
+ public function test_basic_query_still_uses_no_found_rows(): void {
+ \WC_Helper_Order::create_order();
+
+ $this->sut->prepare_items();
+ $query_args = $this->get_order_query_args();
+
+ $this->assertTrue( $query_args['no_found_rows'] ?? false, 'A basic query should use the cache fast path' );
+ }
}