Commit f2b42449dad for woocommerce

commit f2b42449dad168ed27a393372a5ba263cd9fec25
Author: AnnaMag <AnnaMag@users.noreply.github.com>
Date:   Wed Nov 25 19:55:37 2026 +0100

    Agent readiness: best sellers first on large catalogs, daily scan at night, sales read in SQL (#71439)

    * Agent readiness: best sellers first on large catalogs, daily scan at night, sales read in SQL

    On a catalog over the 5,000 product limit, the scan takes the best sellers
    of the last 90 days first, then the most recently changed products. A saved
    product is already checked again on save, and a best seller nobody edits was
    never checked. Catalogs that fit the limit are unchanged.

    The daily run is scheduled for a fixed minute between 1:00 and 5:00 on the
    store's clock, at least 6 hours after the run that schedules it, instead of
    24 hours after the last run started.

    ProductSales::last_days() sums the store total and lists the top products in
    SQL, instead of loading every sold product's sales into PHP.

    WOOAI-1843

    * Skip ineligible products when choosing bestsellers for a large catalog

    * Mark the large-catalog scan changelog as a dev entry

    * Keep ProductScan::start() compatible with existing overrides

    * Skip the best seller query when a scan will not rank

    A store with too few orders, no net sales, or an incomplete Analytics import was still grouping 90 days of sales for a list the scan throws away.

    Co-authored-by: Cursor <cursoragent@cursor.com>

    * Align the scan assignment with the surrounding lines

diff --git a/plugins/woocommerce/changelog/update-agent-readiness-scan-large-stores b/plugins/woocommerce/changelog/update-agent-readiness-scan-large-stores
new file mode 100644
index 00000000000..f059a104a3e
--- /dev/null
+++ b/plugins/woocommerce/changelog/update-agent-readiness-scan-large-stores
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: AI shopping health: best sellers first on catalogs over 5,000 products, daily check at night in site time, sales read in SQL. The feature is unreleased.
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php b/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
index 66bbc12e474..89ca9a9214a 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
@@ -229,7 +229,7 @@ class AgentReadiness {
 	/**
 	 * Run every check over the catalog, in this request, without storing anything.
 	 *
-	 * @return array{generated_at:string,products:int,available:int,hidden_from_catalog:int,unsupported_types:int,store_checks:array<int,array<string,mixed>>,declared:array<int,array{id:string,name:string,found:bool|null}>,channels:array<string,array<string,mixed>>,checks:array<int,array<string,mixed>>,truncated:bool,pages_best_seller?:bool,sales:array{days:int,orders:int,imported:bool}|null}
+	 * @return array{generated_at:string,products:int,available:int,hidden_from_catalog:int,unsupported_types:int,store_checks:array<int,array<string,mixed>>,declared:array<int,array{id:string,name:string,found:bool|null}>,channels:array<string,array<string,mixed>>,checks:array<int,array<string,mixed>>,truncated:bool,bestsellers_first:bool,bestsellers_count:int,pages_best_seller?:bool,sales:array{days:int,orders:int,imported:bool}|null}
 	 */
 	public function get_report(): array {
 		$scan  = $this->start_scan();
@@ -246,37 +246,43 @@ class AgentReadiness {
 	 * Start a scan: the rules, the sales period and the products to test, before any is tested.
 	 * Each later step runs from what this returns, so a scan can go on in another request.
 	 *
-	 * @return array{ids:array<int,int>,position:int,sales:array{days:int,since:string,orders:int,imported:bool,total:float}|null,ranked:bool,best_seller:int,scan:array<string,mixed>}
+	 * @return array{ids:array<int,int>,position:int,sales:array{days:int,since:string,orders:int,imported:bool,total:float}|null,ranked:bool,best_seller:int,bestsellers_first:bool,bestsellers_count:int,scan:array<string,mixed>}
 	 */
 	private function start_scan(): array {
 		// Rebuild the rules for each scan: a long-running process may have fetched a new rules file since.
 		$this->active_rules = null;
 		$this->product_scan = null;
 		$sales              = $this->product_sales->last_days();
-		$product_scan       = new ProductScan();
-		$ids                = $product_scan->start();
 		$ranked             = null !== $sales && $sales['imported'] && $sales['orders'] >= ProductSales::MIN_ORDERS && $sales['total'] > 0;
-		// Keep only the best seller id for page checks at finish; the full sales map is not stored between batches.
-		$best_seller = 0;
-		if ( $ranked ) {
-			$by_product = array_filter( $sales['by_product'], static fn( $amount ): bool => $amount > 0 );
-			arsort( $by_product );
-			$best_seller = (int) ( array_key_first( $by_product ) ?? 0 );
-		}
+		$since              = null === $sales ? '' : $sales['since'];
+		// The seller ids are a second query, so a store the scan will not rank never groups its sales.
+		$best_sellers = $ranked ? $this->product_sales->more_top_products( $since, 0, ProductSales::TOP_PRODUCTS ) : array();
+		$product_scan = new ProductScan();
+		$more         = $ranked && count( $best_sellers ) >= ProductScan::PRODUCT_LIMIT
+			? function ( int $offset, int $limit ) use ( $since ): array {
+				return $this->product_sales->more_top_products( $since, $offset, $limit );
+			}
+			: null;
+		$ids          = $product_scan->start_best_sellers_first( $best_sellers, $more );
+		// Only the best seller's id is kept, for the page checks at finish.
+		$best_seller = (int) ( $best_sellers[0] ?? 0 );
 		return array(
-			'ids'         => $ids,
-			'position'    => 0,
+			'ids'               => $ids,
+			'position'          => 0,
 			// The period and totals only: each batch reads its own products' sales, so the whole store's are never kept.
-			'sales'       => null === $sales ? null : array(
+			'sales'             => null === $sales ? null : array(
 				'days'     => $sales['days'],
 				'since'    => $sales['since'],
 				'orders'   => $sales['orders'],
 				'imported' => $sales['imported'],
 				'total'    => $sales['total'],
 			),
-			'ranked'      => $ranked,
-			'best_seller' => $best_seller,
-			'scan'        => $product_scan->state(),
+			'ranked'            => $ranked,
+			'best_seller'       => $best_seller,
+			// Whether a catalog over the limit was listed with its bestsellers first, and how many of those led the list.
+			'bestsellers_first' => $product_scan->best_sellers_first(),
+			'bestsellers_count' => $product_scan->bestsellers_count(),
+			'scan'              => $product_scan->state(),
 		);
 	}

@@ -307,7 +313,7 @@ class AgentReadiness {
 	 * Build the report once every batch is tested. The store output checks request the store's own pages, so they run here, once.
 	 *
 	 * @param array<string, mixed> $scan The scan after its last batch.
-	 * @return array{generated_at:string,products:int,available:int,hidden_from_catalog:int,unsupported_types:int,store_checks:array<int,array<string,mixed>>,declared:array<int,array{id:string,name:string,found:bool|null}>,channels:array<string,array<string,mixed>>,checks:array<int,array<string,mixed>>,truncated:bool,pages_best_seller:bool,sales:array{days:int,orders:int,imported:bool}|null,shared_gtins?:array<int,string>}
+	 * @return array{generated_at:string,products:int,available:int,hidden_from_catalog:int,unsupported_types:int,store_checks:array<int,array<string,mixed>>,declared:array<int,array{id:string,name:string,found:bool|null}>,channels:array<string,array<string,mixed>>,checks:array<int,array<string,mixed>>,truncated:bool,bestsellers_first:bool,bestsellers_count:int,pages_best_seller:bool,sales:array{days:int,orders:int,imported:bool}|null,shared_gtins?:array<int,string>}
 	 */
 	private function finish_scan( array $scan ): array {
 		$active       = $this->get_active_rules();
@@ -351,6 +357,9 @@ class AgentReadiness {
 			'channels'            => $product_scan->channel_totals(),
 			'checks'              => $checks,
 			'truncated'           => $product_scan->truncated(),
+			// On a scan that stopped at the limit: whether bestsellers led, and how many of the checked products they are.
+			'bestsellers_first'   => ! empty( $scan['bestsellers_first'] ),
+			'bestsellers_count'   => (int) ( $scan['bestsellers_count'] ?? 0 ),
 			// How sales shares were measured: null while Analytics is off.
 			'sales'               => null === $sales ? null : array(
 				'days'     => $sales['days'],
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php b/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
index 25f7d00d3a6..bd5d9544d69 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
@@ -33,11 +33,17 @@ class ProductSales {
 	private const IMPORTED_SHARE = 0.9;

 	/**
-	 * Net sales by product id and by variation id, their total, the number of orders, and whether
-	 * Analytics holds the store's orders for the period, or null while Analytics is off. `since` is
-	 * the period's start, for reading the same period again for some products with for_products().
+	 * How many best sellers one page of more_top_products() returns: as many as one scan checks.
+	 */
+	public const TOP_PRODUCTS = ProductScan::PRODUCT_LIMIT;
+
+	/**
+	 * The store's net sales, the number of orders, and whether Analytics holds the store's orders
+	 * for the period, or null while Analytics is off. `since` is the period's start, for reading
+	 * the same period again for some products with for_products(), and for the best sellers with
+	 * more_top_products() when the scan ranks by sales. Sales per product stay in the database.
 	 *
-	 * @return array{days:int,since:string,orders:int,imported:bool,total:float,by_product:array<int,float>,by_variation:array<int,float>}|null
+	 * @return array{days:int,since:string,orders:int,imported:bool,total:float}|null
 	 */
 	public function last_days(): ?array {
 		global $wpdb;
@@ -65,16 +71,14 @@ class ProductSales {
 			)
 		);
 		// phpcs:enable
-		$sales = self::revenue( $since, $excluded, null );
+		$total = self::total( $since, $excluded );

 		return array(
-			'days'         => self::DAYS,
-			'since'        => $since,
-			'orders'       => $orders,
-			'imported'     => self::is_imported( $orders, self::store_orders( $start, $excluded ) ),
-			'total'        => max( 0.0, array_sum( $sales['by_product'] ) ),
-			'by_product'   => $sales['by_product'],
-			'by_variation' => $sales['by_variation'],
+			'days'     => self::DAYS,
+			'since'    => $since,
+			'orders'   => $orders,
+			'imported' => self::is_imported( $orders, self::store_orders( $start, $excluded ) ),
+			'total'    => max( 0.0, $total ),
 		);
 	}

@@ -91,16 +95,113 @@ class ProductSales {
 	}

 	/**
-	 * Net sales by product and by variation since a date, for every product or only some.
+	 * The store's net sales since a date, refunds taken off.
+	 *
+	 * @param string             $since    Period start, in the site's time zone.
+	 * @param array<int, string> $excluded Order statuses Analytics leaves out.
+	 *
+	 * @throws \RuntimeException When the sales query fails.
+	 */
+	private static function total( string $since, array $excluded ): float {
+		global $wpdb;
+
+		$lookup = $wpdb->prefix . 'wc_order_product_lookup';
+		$stats  = $wpdb->prefix . 'wc_order_stats';
+		$not_in = self::not_in( $excluded );
+
+		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Table names from $wpdb, placeholders built for the statuses; the scan reads this once, in the background.
+		$wpdb->last_error = '';
+		$total            = $wpdb->get_var(
+			$wpdb->prepare(
+				"SELECT SUM( lookup.product_net_revenue )
+				FROM {$lookup} AS lookup
+				INNER JOIN {$stats} AS stats ON stats.order_id = lookup.order_id
+				WHERE lookup.date_created >= %s {$not_in}",
+				array_merge( array( $since ), $excluded )
+			)
+		);
+		// phpcs:enable
+		$error = self::db_error();
+		if ( '' !== $error ) {
+			throw new \RuntimeException( esc_html( 'Agent readiness sales query failed. ' . $error ) );
+		}
+		return (float) $total;
+	}
+
+	/**
+	 * A page of published products by net sales, highest first. Offset 0 is the first page.
+	 * A deleted or unpublished product is left out here; its revenue still counts in the total.
+	 *
+	 * @since 11.4.0
+	 *
+	 * @param string $since  Period start from last_days().
+	 * @param int    $offset How many leading products to skip.
+	 * @param int    $limit  How many to return.
+	 * @return array<int, int>
+	 *
+	 * @throws \RuntimeException When the sales query fails.
+	 */
+	public function more_top_products( string $since, int $offset, int $limit ): array {
+		if ( $offset < 0 || $limit < 1 ) {
+			return array();
+		}
+		return self::top_products( $since, self::excluded_statuses(), $offset, $limit );
+	}
+
+	/**
+	 * Ids of the published products with the most net sales since a date, highest first.
+	 * A variation counts toward its parent. Products whose sales net to nothing or less are left out.
+	 *
+	 * @param string             $since    Period start, in the site's time zone.
+	 * @param array<int, string> $excluded Order statuses Analytics leaves out.
+	 * @param int                $offset   How many leading products to skip.
+	 * @param int                $limit    How many to return.
+	 * @return array<int, int>
+	 *
+	 * @throws \RuntimeException When the sales query fails.
+	 */
+	private static function top_products( string $since, array $excluded, int $offset = 0, int $limit = self::TOP_PRODUCTS ): array {
+		global $wpdb;
+
+		$lookup = $wpdb->prefix . 'wc_order_product_lookup';
+		$stats  = $wpdb->prefix . 'wc_order_stats';
+		$not_in = self::not_in( $excluded );
+
+		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Table names from $wpdb, placeholders built for the statuses, limit and offset; the scan reads this in the background.
+		$wpdb->last_error = '';
+		$ids              = $wpdb->get_col(
+			$wpdb->prepare(
+				"SELECT lookup.product_id
+				FROM {$lookup} AS lookup
+				INNER JOIN {$wpdb->posts} AS posts ON posts.ID = lookup.product_id AND posts.post_type = 'product' AND posts.post_status = 'publish'
+				INNER JOIN {$stats} AS stats ON stats.order_id = lookup.order_id
+				WHERE lookup.date_created >= %s {$not_in}
+				GROUP BY lookup.product_id
+				HAVING SUM( lookup.product_net_revenue ) > 0
+				ORDER BY SUM( lookup.product_net_revenue ) DESC, lookup.product_id ASC
+				LIMIT %d OFFSET %d",
+				array_merge( array( $since ), $excluded, array( $limit, $offset ) )
+			)
+		);
+		// phpcs:enable
+		$error = self::db_error();
+		if ( '' !== $error ) {
+			throw new \RuntimeException( esc_html( 'Agent readiness sales query failed. ' . $error ) );
+		}
+		return array_map( 'intval', $ids );
+	}
+
+	/**
+	 * Net sales by product and by variation since a date, for some products.
 	 *
-	 * @param string               $since       Period start, in the site's time zone.
-	 * @param array<int, string>   $excluded    Order statuses Analytics leaves out.
-	 * @param array<int, int>|null $product_ids Product ids, or null for every product.
+	 * @param string             $since       Period start, in the site's time zone.
+	 * @param array<int, string> $excluded    Order statuses Analytics leaves out.
+	 * @param array<int, int>    $product_ids Product ids.
 	 * @return array{by_product:array<int,float>,by_variation:array<int,float>}
 	 *
 	 * @throws \RuntimeException When the sales query fails.
 	 */
-	private static function revenue( string $since, array $excluded, ?array $product_ids ): array {
+	private static function revenue( string $since, array $excluded, array $product_ids ): array {
 		global $wpdb;

 		$by_product   = array();
@@ -111,7 +212,7 @@ class ProductSales {
 		$lookup   = $wpdb->prefix . 'wc_order_product_lookup';
 		$stats    = $wpdb->prefix . 'wc_order_stats';
 		$not_in   = self::not_in( $excluded );
-		$products = null === $product_ids ? '' : 'AND lookup.product_id IN ( ' . implode( ', ', array_fill( 0, count( $product_ids ), '%d' ) ) . ' )';
+		$products = 'AND lookup.product_id IN ( ' . implode( ', ', array_fill( 0, count( $product_ids ), '%d' ) ) . ' )';

 		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Table names from $wpdb, placeholders built for the statuses and product ids; the scan reads this in the background.
 		$wpdb->last_error = '';
@@ -122,7 +223,7 @@ class ProductSales {
 				INNER JOIN {$stats} AS stats ON stats.order_id = lookup.order_id
 				WHERE lookup.date_created >= %s {$not_in} {$products}
 				GROUP BY lookup.product_id, lookup.variation_id",
-				array_merge( array( $since ), $excluded, array_map( 'intval', $product_ids ?? array() ) )
+				array_merge( array( $since ), $excluded, array_map( 'intval', $product_ids ) )
 			),
 			ARRAY_A
 		);
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ProductScan.php b/plugins/woocommerce/src/Internal/AgentReadiness/ProductScan.php
index 851eefff3ec..95192f3412d 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ProductScan.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ProductScan.php
@@ -11,7 +11,7 @@ defined( 'ABSPATH' ) || exit;
  * One pass over the published catalog for the readiness checks.
  *
  * Walks published simple and variable products in batches, most recently
- * modified first, tests each against every rule once and tallies product
+ * modified first (best sellers first on a catalog over PRODUCT_LIMIT), tests each against every rule once and tallies product
  * statuses per channel. Stops after PRODUCT_LIMIT products so the scan stays
  * inside one request. Products set to Hidden are the merchant's choice and
  * agents can't buy other product types through UCP yet, so both are counted,
@@ -26,6 +26,12 @@ class ProductScan {

 	public const PRODUCT_LIMIT = 5000;

+	/**
+	 * Sales pages read when earlier pages are products the scan does not check.
+	 * Each page repeats the aggregation, so a catalog of other product types stays bounded.
+	 */
+	private const SELLER_PAGES = 10;
+
 	public const SUPPORTED_TYPES = array( 'simple', 'variable' );

 	/**
@@ -122,6 +128,20 @@ class ProductScan {
 	 */
 	private bool $truncated = false;

+	/**
+	 * Whether start() put best sellers ahead of the newest changes.
+	 *
+	 * @var bool
+	 */
+	private bool $best_sellers_first = false;
+
+	/**
+	 * How many of the products start() returns are bestsellers it checked.
+	 *
+	 * @var int
+	 */
+	private int $bestsellers_count = 0;
+
 	/**
 	 * Called with each product id and its failures during test(). Cleared when that batch ends.
 	 *
@@ -164,6 +184,22 @@ class ProductScan {
 	 * @throws \RuntimeException When the product list query fails.
 	 */
 	public function start(): array {
+		return $this->start_best_sellers_first( array() );
+	}
+
+	/**
+	 * Same list as start(), with bestsellers ahead of the newest changes when the catalog is over the limit.
+	 * A saved product is checked again on save; one nobody edits would never be.
+	 *
+	 * @since 11.4.0
+	 *
+	 * @param array<int, int> $best_sellers       Product ids with the most sales first, or none to go by last change only.
+	 * @param callable|null   $more_best_sellers Next page `(int $offset, int $limit): array<int, int>`, when that list may continue.
+	 * @return array<int, int> Product ids.
+	 *
+	 * @throws \RuntimeException When the product list query fails.
+	 */
+	public function start_best_sellers_first( array $best_sellers, ?callable $more_best_sellers = null ): array {
 		$this->results             = array();
 		$this->products            = 0;
 		$this->statuses            = array();
@@ -171,41 +207,135 @@ class ProductScan {
 		$this->available           = self::count_published( self::count_query( self::COUNT_AVAILABLE ) );
 		$this->unsupported_types   = self::count_published( self::count_query( self::COUNT_UNSUPPORTED ) );

-		global $wpdb;
-		// An ids query returns before posts_results runs, so read the error the query left instead.
-		$wpdb->last_error = '';
-		$query            = new \WP_Query(
+		// One more than the limit, to tell a catalog cut short from one that fits.
+		$product_ids              = self::list_products(
 			array(
-				'post_type'      => 'product',
-				'post_status'    => 'publish',
-				// One more than the limit, to tell a catalog cut short from one that fits.
 				'posts_per_page' => self::PRODUCT_LIMIT + 1,
-				'fields'         => 'ids',
 				'orderby'        => array(
 					'modified' => 'DESC',
 					'ID'       => 'DESC',
 				),
-				'no_found_rows'  => true,
-				// A failed query would be cached as an empty list, and the next scan would read it without an error.
-				'cache_results'  => false,
-				'tax_query'      => self::count_query( self::COUNT_AVAILABLE ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
 			)
 		);
-		$query_failed = '' !== self::db_error();
+		$this->truncated          = count( $product_ids ) > self::PRODUCT_LIMIT;
+		$this->best_sellers_first = false;
+		$this->bestsellers_count  = 0;
+		$eligible                 = $this->truncated ? $this->eligible_sellers( $best_sellers, $more_best_sellers ) : array();
+		if ( array() !== $eligible ) {
+			$this->best_sellers_first = true;
+			$this->bestsellers_count  = count( $eligible );
+			$product_ids              = array_values( array_unique( array_merge( $eligible, $product_ids ) ) );
+		}
+		return array_slice( $product_ids, 0, self::PRODUCT_LIMIT );
+	}

-		$product_ids = array_map(
-			static function ( $post ): int {
-				return $post instanceof \WP_Post ? $post->ID : (int) $post;
-			},
-			is_array( $query->posts ) ? $query->posts : array()
+	/**
+	 * Bestsellers the scan checks, most sales first, reading further pages while earlier ones
+	 * are hidden, unpublished or another type. Stops at PRODUCT_LIMIT.
+	 *
+	 * @param array<int, int> $best_sellers       First page, most sales first.
+	 * @param callable|null   $more_best_sellers Next page, or null when $best_sellers is the whole list.
+	 * @return array<int, int>
+	 *
+	 * @throws \RuntimeException When a product list query fails.
+	 */
+	private function eligible_sellers( array $best_sellers, ?callable $more_best_sellers ): array {
+		$eligible = array();
+		$seen     = array();
+		$page     = self::positive_ids( $best_sellers );
+		$offset   = 0;
+		$pages    = 0;
+		$room     = self::PRODUCT_LIMIT;
+		while ( array() !== $page && $pages < self::SELLER_PAGES && $room > 0 ) {
+			++$pages;
+			$page    = array_slice( $page, 0, self::PRODUCT_LIMIT );
+			$offset += count( $page );
+			foreach ( self::eligible_ids( $page ) as $id ) {
+				if ( isset( $seen[ $id ] ) ) {
+					continue;
+				}
+				$seen[ $id ] = true;
+				$eligible[]  = $id;
+				--$room;
+				if ( 0 === $room ) {
+					break;
+				}
+			}
+			if ( 0 === $room || count( $page ) < self::PRODUCT_LIMIT || ! is_callable( $more_best_sellers ) ) {
+				break;
+			}
+			$next = $more_best_sellers( $offset, self::PRODUCT_LIMIT );
+			$page = self::positive_ids( is_array( $next ) ? $next : array() );
+		}
+		return $eligible;
+	}
+
+	/**
+	 * Ids from a sales page that the scan checks, in that page's order.
+	 *
+	 * @param array<int, int> $ids Product ids, most sales first.
+	 * @return array<int, int>
+	 *
+	 * @throws \RuntimeException When the product list query fails.
+	 */
+	private static function eligible_ids( array $ids ): array {
+		if ( array() === $ids ) {
+			return array();
+		}
+		// The same query as the catalog list, so a hidden, unpublished or other type is left out.
+		return self::list_products(
+			array(
+				'posts_per_page' => count( $ids ),
+				'post__in'       => $ids,
+				'orderby'        => 'post__in',
+			)
+		);
+	}
+
+	/**
+	 * Product ids, dropping empties. A sales row can name a product id of 0.
+	 *
+	 * @param array<mixed> $ids Ids from the sales query or its next page.
+	 * @return array<int, int>
+	 */
+	private static function positive_ids( array $ids ): array {
+		return array_values( array_filter( array_map( 'intval', $ids ) ) );
+	}
+
+	/**
+	 * Ids of published products the scan checks, for start().
+	 *
+	 * @param array<string, mixed> $args Which of them, and in what order.
+	 * @return array<int, int>
+	 *
+	 * @throws \RuntimeException When the query fails.
+	 */
+	private static function list_products( array $args ): array {
+		global $wpdb;
+		// An ids query returns before posts_results runs, so read the error the query left instead.
+		$wpdb->last_error = '';
+		$query            = new \WP_Query(
+			$args + array(
+				'post_type'     => 'product',
+				'post_status'   => 'publish',
+				'fields'        => 'ids',
+				'no_found_rows' => true,
+				// A failed query would be cached as an empty list, and the next scan would read it without an error.
+				'cache_results' => false,
+				'tax_query'     => self::count_query( self::COUNT_AVAILABLE ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
+			)
 		);
 		// Only a database error is a failed list, whatever the counts say: they read 0 when their own queries fail.
 		// An empty success publishes a scan of what is left.
-		if ( $query_failed ) {
+		if ( '' !== self::db_error() ) {
 			throw new \RuntimeException( 'Agent readiness could not list products to scan.' );
 		}
-		$this->truncated = count( $product_ids ) > self::PRODUCT_LIMIT;
-		return array_slice( $product_ids, 0, self::PRODUCT_LIMIT );
+		return array_map(
+			static function ( $post ): int {
+				return $post instanceof \WP_Post ? $post->ID : (int) $post;
+			},
+			is_array( $query->posts ) ? $query->posts : array()
+		);
 	}

 	/**
@@ -553,6 +683,25 @@ class ProductScan {
 		return $this->truncated;
 	}

+	/**
+	 * Whether start() put best sellers ahead of the newest changes: only on a catalog over
+	 * PRODUCT_LIMIT, and only when at least one best seller is a product the scan checks.
+	 *
+	 * @since 11.4.0
+	 */
+	public function best_sellers_first(): bool {
+		return $this->best_sellers_first;
+	}
+
+	/**
+	 * How many leading products are bestsellers the scan checks. PRODUCT_LIMIT when they fill the list.
+	 *
+	 * @since 11.4.0
+	 */
+	public function bestsellers_count(): int {
+		return $this->bestsellers_count;
+	}
+
 	/**
 	 * Whether more than one published product carries this GTIN, counting a
 	 * variable product and its variations once. GTINs compare without leading zeros.
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/README.md b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
index 600fa437f16..e13cceb483d 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/README.md
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
@@ -160,11 +160,13 @@ array(
 			'fix'         => '…',
 			'channels'    => array( 'chatgpt' => array( 'field' => 'brand', 'effect' => 'not_listable' ) ),
 			'count'       => 20,
-			'product_ids' => array( 12, 34 ), // Up to 10, most recently modified first.
+			'product_ids' => array( 12, 34 ), // Up to 10, in the order they were checked.
 			'fix_url'     => 'https://example.com/wp-admin/edit.php?post_type=product',
 		),
 	),
 	'truncated'    => false, // True when the scan stopped at 5,000 products.
+	'bestsellers_first' => false, // On a truncated scan: true when bestsellers led the list.
+	'bestsellers_count' => 0, // How many of the checked products are those bestsellers. The limit, when they fill it.
 )
 ```

@@ -184,9 +186,9 @@ Per check, `channels` maps a channel id to the feed field and the effect, the sa

 ## Background scan and REST

-"Check your store" on WooCommerce > Sales readiness, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). Each run schedules the next one a day later, before scanning, so a failed scan doesn't stop the daily refresh. Cancelling the scheduled actions under Tools > Scheduled Actions stops the chain until the next manual check. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the Sales readiness page says so and the scan stays queued. The scan never runs in a page or REST request.
+"Check your store" on WooCommerce > Sales readiness, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). Each run schedules the next one for the coming night before scanning (`ScheduledScan::next_daily_run()`: a minute between 1:00 and 5:00 on the store's clock, fixed per store by its address), so a failed scan doesn't stop the daily refresh and a run that starts late doesn't move the next one. A slot less than 6 hours away is left for the night after. Cancelling the scheduled actions under Tools > Scheduled Actions stops the chain until the next manual check. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the Sales readiness page says so and the scan stays queued. The scan never runs in a page or REST request.

-A scan runs as a chain of actions (`NEXT_HOOK`, with the scan's id), so no action tests more than one batch of products. The first lists the products to test, newest change first, and stores that list with the totals in the `woocommerce_agent_readiness_scan` option (not autoloaded). Starting still reads the store's 90-day sales once (for the total, whether ranking applies, and the best seller for page checks); each later batch reads only its own products' sales, so the whole store's sales map is never kept between actions. Each action tests the next batch of 200, saves the totals and queues the next; the last builds the report, with the store output checks, and stores it. Before testing, an action queues a retry RETRY_AFTER (10 minutes) later, which it removes when it finishes, so a batch that ends early, as on a timeout, is tried again from the last finished batch. After MAX_ATTEMPTS (3) tries of the same batch, the scan stops and the last report stays. Giving up, cancelling, or replacing a scan removes failure rows it wrote for products the last report never covered, so the Products list stays aligned with that report. A new request (or the daily run) replaces a scan in progress and starts over; the replaced scan's actions change nothing. `refresh_report()` runs the same steps in one request.
+A scan runs as a chain of actions (`NEXT_HOOK`, with the scan's id), so no action tests more than one batch of products. The first lists the products to test, newest change first (on a catalog over 5,000 products with sales to rank by, best sellers of the last 90 days first, skipping any the scan does not check and reading the next sellers until the limit is filled or the sales run out, then newest change), and stores that list with the totals in the `woocommerce_agent_readiness_scan` option (not autoloaded). Starting reads the store's 90-day totals once (`ProductSales::last_days()`). When those totals say the scan can rank, it then reads the best seller ids, summed in SQL and limited to published products, so memory doesn't grow with the number of products sold. A page of sellers the scan cannot check is followed by the next page, up to ten pages. Each later batch reads only its own products' sales, so the whole store's sales map is never loaded. Each action tests the next batch of 200, saves the totals and queues the next; the last builds the report, with the store output checks, and stores it. Before testing, an action queues a retry RETRY_AFTER (10 minutes) later, which it removes when it finishes, so a batch that ends early, as on a timeout, is tried again from the last finished batch. After MAX_ATTEMPTS (3) tries of the same batch, the scan stops and the last report stays. Giving up, cancelling, or replacing a scan removes failure rows it wrote for products the last report never covered, so the Products list stays aligned with that report. A new request (or the daily run) replaces a scan in progress and starts over; the replaced scan's actions change nothing. `refresh_report()` runs the same steps in one request.

 On a store with 11,000 products, a scan (stopping at 5,000) took about 4 seconds and 144 MB. A product saved since the scan is already reflected in the counts, as described under Failures per product.

@@ -194,7 +196,7 @@ On a store with 11,000 products, a scan (stopping at 5,000) took about 4 seconds

 The same shape is meant for every consumer: WooCommerce > Sales readiness and AI shopping, an outside scan of a store, and extensions that rank the findings by sales or offer fixes. Check and channel ids are stable keys.

-The scan walks published simple and variable products not set to Hidden in batches of 200, most recently modified first, primes meta, terms, images and variations per batch, and stops at 5,000 products. The list of products is read once when the scan starts, so a product changed while it runs neither moves nor gets tested twice; a product saved meanwhile stores its own results, as described under Failures per product.
+The scan walks published simple and variable products not set to Hidden in batches of 200, most recently modified first (best sellers first on a catalog over 5,000 products, see above), primes meta, terms, images and variations per batch, and stops at 5,000 products. The list of products is read once when the scan starts, so a product changed while it runs neither moves nor gets tested twice; a product saved meanwhile stores its own results, as described under Failures per product.

 ## Abilities

diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
index 33b9510f2df..7f0549fdd8b 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
@@ -307,14 +307,19 @@ class ReadinessCheckPage implements RegisterHooksInterface {
 		} elseif ( $pending ) {
 			$message = __( 'Checking your store', 'woocommerce' );
 		}
-		$truncated = null;
+		$truncated   = null;
+		$sample_note = null;
 		if ( null !== $report && ! empty( $report['truncated'] ) ) {
-			$available = (int) ( $report['available'] ?? 0 );
-			$truncated = $available > ProductScan::PRODUCT_LIMIT
-				/* translators: 1: number of products checked, 2: number of products in the store. */
-				? sprintf( __( 'Product checks covered the %1$s products you updated most recently, out of %2$s. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ), number_format_i18n( ProductScan::PRODUCT_LIMIT ), number_format_i18n( $available ) )
-				/* translators: %s: number of products checked. Reports from before the total was stored. */
-				: sprintf( __( 'Product checks covered the %s products you updated most recently. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ), number_format_i18n( ProductScan::PRODUCT_LIMIT ) );
+			$available   = (int) ( $report['available'] ?? 0 );
+			$with_total  = $available > ProductScan::PRODUCT_LIMIT;
+			$sample_note = self::truncated_copy(
+				$with_total,
+				$with_total && (int) ( $report['bestsellers_count'] ?? 0 ) >= ProductScan::PRODUCT_LIMIT,
+				$with_total && ! empty( $report['bestsellers_first'] )
+			);
+			$truncated   = $with_total
+				? sprintf( $sample_note['checked'], number_format_i18n( ProductScan::PRODUCT_LIMIT ), number_format_i18n( $available ) )
+				: sprintf( $sample_note['checked'], number_format_i18n( ProductScan::PRODUCT_LIMIT ) );
 		}
 		return array(
 			'title'        => __( 'AI shopping health', 'woocommerce' ),
@@ -342,11 +347,7 @@ class ReadinessCheckPage implements RegisterHooksInterface {
 			'overview'     => array(
 				'shopping' => $this->shopping_card( $checks ),
 				// After the description, when the last check stopped at the product limit.
-				'based_on' => null === $truncated ? null : sprintf(
-					/* translators: %s: number of products checked. */
-					__( 'Based on your %s most recently changed products.', 'woocommerce' ),
-					number_format_i18n( ProductScan::PRODUCT_LIMIT )
-				),
+				'based_on' => null === $sample_note ? null : sprintf( $sample_note['based_on'], number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
 				'view_all' => array(
 					'href' => self::url(),
 					'text' => __( 'View all checks', 'woocommerce' ),
@@ -355,6 +356,48 @@ class ReadinessCheckPage implements RegisterHooksInterface {
 		);
 	}

+	/**
+	 * The checked note and the "based on" line when a scan stopped at the product limit.
+	 * Bestsellers fill the note on their own when they take every slot.
+	 *
+	 * @param bool $with_total  Whether the report stored how many products the store has.
+	 * @param bool $only_sellers Whether bestsellers fill every checked slot.
+	 * @param bool $then_recent  Whether bestsellers lead and recently changed products follow.
+	 * @return array{checked:string,based_on:string}
+	 */
+	private static function truncated_copy( bool $with_total, bool $only_sellers, bool $then_recent ): array {
+		if ( ! $with_total ) {
+			return array(
+				/* translators: %s: number of products checked. Reports from before the total was stored. */
+				'checked'  => __( 'Product checks covered the %s products you updated most recently. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ),
+				/* translators: %s: number of products checked. */
+				'based_on' => __( 'Based on your %s most recently changed products.', 'woocommerce' ),
+			);
+		}
+		if ( $only_sellers ) {
+			return array(
+				/* translators: 1: number of products checked, 2: number of products in the store. */
+				'checked'  => __( 'Product checks covered %1$s of your %2$s products: your bestsellers. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ),
+				/* translators: %s: number of products checked. */
+				'based_on' => __( 'Based on your %s bestsellers.', 'woocommerce' ),
+			);
+		}
+		if ( $then_recent ) {
+			return array(
+				/* translators: 1: number of products checked, 2: number of products in the store. */
+				'checked'  => __( 'Product checks covered %1$s of your %2$s products: your bestsellers first, then the ones you updated most recently. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ),
+				/* translators: %s: number of products checked. */
+				'based_on' => __( 'Based on %s products: your bestsellers first, then the ones you changed most recently.', 'woocommerce' ),
+			);
+		}
+		return array(
+			/* translators: 1: number of products checked, 2: number of products in the store. */
+			'checked'  => __( 'Product checks covered the %1$s products you updated most recently, out of %2$s. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', 'woocommerce' ),
+			/* translators: %s: number of products checked. */
+			'based_on' => __( 'Based on your %s most recently changed products.', 'woocommerce' ),
+		);
+	}
+
 	/**
 	 * The Overview's AI shopping card: its badge once AI shopping is on, whether AI assistants can shop the store and how
 	 * many setup steps are left, and a button to the settings. Before the UCP setting is first saved, it invites the merchant to set up AI
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReportAbility.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReportAbility.php
index c8a1a58a5f7..caa74b3cbea 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ReportAbility.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReportAbility.php
@@ -199,7 +199,7 @@ class ReportAbility implements AbilityDefinition {
 									'count'       => array( 'type' => 'integer' ),
 									'product_ids' => array(
 										'type'        => 'array',
-										'description' => __( 'Up to 10 failing products, most recently modified first.', 'woocommerce' ),
+										'description' => __( 'Up to 10 failing products, in the order they were checked.', 'woocommerce' ),
 										'items'       => array( 'type' => 'integer' ),
 									),
 									'sales_share' => array(
@@ -226,6 +226,14 @@ class ReportAbility implements AbilityDefinition {
 							),
 						),
 						'truncated'           => array( 'type' => 'boolean' ),
+						'bestsellers_first'   => array(
+							'type'        => 'boolean',
+							'description' => __( 'On a truncated check: whether the products checked start with bestsellers. False when they are the most recently modified only.', 'woocommerce' ),
+						),
+						'bestsellers_count'   => array(
+							'type'        => 'integer',
+							'description' => __( 'How many of the checked products are bestsellers placed ahead of the most recently modified. Equal to the check limit when those bestsellers fill it. Zero when the check is the most recently modified only.', 'woocommerce' ),
+						),
 						'pages_best_seller'   => array(
 							'type'        => 'boolean',
 							'description' => __( 'Whether the up to five product pages the page checks read start with the best seller. False when they start with the newest product.', 'woocommerce' ),
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php b/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
index 02c25829bda..2f9e40f7329 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
@@ -12,7 +12,8 @@ defined( 'ABSPATH' ) || exit;
  * Runs the readiness scan in Action Scheduler instead of the page request,
  * and keeps the stored report fresh with one run a day.
  *
- * Each run schedules the next one a day later, so nothing is queued until a
+ * Each run schedules the next one for the coming night, on the store's clock
+ * (next_daily_run()), so nothing is queued until a
  * merchant or the REST API asks for the first scan, and no request pays for a
  * scheduling check. The next run is scheduled before the scan, so a scan that
  * fails or times out does not end the chain. Cancelling the scheduled actions
@@ -45,6 +46,18 @@ class ScheduledScan implements RegisterHooksInterface {

 	public const GROUP = 'woocommerce-agent-readiness';

+	/**
+	 * Hours of the night, on the store's clock, between which the daily scan is scheduled.
+	 */
+	public const NIGHT_FROM = 1;
+
+	public const NIGHT_TO = 5;
+
+	/**
+	 * The least time between a run and the daily run it schedules.
+	 */
+	public const MIN_GAP = 6 * HOUR_IN_SECONDS;
+
 	public const STALLED_AFTER = 10 * MINUTE_IN_SECONDS;

 	/**
@@ -167,13 +180,35 @@ class ScheduledScan implements RegisterHooksInterface {
 	 */
 	public function run(): void {
 		as_unschedule_all_actions( self::DAILY_HOOK, array(), self::GROUP );
-		as_schedule_single_action( time() + DAY_IN_SECONDS, self::DAILY_HOOK, array(), self::GROUP );
+		as_schedule_single_action( self::next_daily_run(), self::DAILY_HOOK, array(), self::GROUP );

 		$this->remote_rules->refresh( array_keys( $this->agent_readiness->get_default_rules() ) );
 		as_unschedule_all_actions( self::NEXT_HOOK );
 		as_schedule_single_action( time(), self::NEXT_HOOK, array( $this->agent_readiness->start_refresh() ), self::GROUP );
 	}

+	/**
+	 * When the next daily scan is due: the next time the store's clock shows its night slot.
+	 * The slot is a minute between NIGHT_FROM and NIGHT_TO, fixed per store by its address,
+	 * so stores on one host don't all start together. A run that starts late doesn't move it.
+	 * A slot less than MIN_GAP away is left for the night after, so a check started late in
+	 * the evening or at night isn't followed by a second one within hours.
+	 *
+	 * @since 11.4.0
+	 *
+	 * @param int|null $time The current time, or null for now.
+	 */
+	public static function next_daily_run( ?int $time = null ): int {
+		$now    = ( new \DateTimeImmutable( '@' . ( $time ?? time() ) ) )->setTimezone( wp_timezone() );
+		$minute = self::NIGHT_FROM * 60 + absint( crc32( home_url() ) ) % ( ( self::NIGHT_TO - self::NIGHT_FROM ) * 60 );
+		$slot   = $now->setTime( intdiv( $minute, 60 ), $minute % 60 );
+		// Twice at most: tonight's slot may be past, and tomorrow's may still be too close.
+		while ( $slot->getTimestamp() - $now->getTimestamp() < self::MIN_GAP ) {
+			$slot = $slot->modify( '+1 day' );
+		}
+		return $slot->getTimestamp();
+	}
+
 	/**
 	 * Test one batch of a scan, then queue the next, or store the report after the last.
 	 *
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/SupportReport.php b/plugins/woocommerce/src/Internal/AgentReadiness/SupportReport.php
index 5588852e405..976f83b7e69 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/SupportReport.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/SupportReport.php
@@ -146,7 +146,12 @@ class SupportReport {
 			'Check status: ' . $state,
 		);
 		if ( null !== $report && ! empty( $report['truncated'] ) ) {
-			$lines[] = sprintf( 'Checked the %s products you changed most recently.', ProductScan::PRODUCT_LIMIT );
+			$count   = (int) ( $report['bestsellers_count'] ?? 0 );
+			$lines[] = $count >= ProductScan::PRODUCT_LIMIT
+				? sprintf( 'Checked %s bestsellers.', ProductScan::PRODUCT_LIMIT )
+				: ( ! empty( $report['bestsellers_first'] )
+					? sprintf( 'Checked %s products: bestsellers first, then the most recently changed.', ProductScan::PRODUCT_LIMIT )
+					: sprintf( 'Checked the %s products you changed most recently.', ProductScan::PRODUCT_LIMIT ) );
 		}
 		return $lines;
 	}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
index 9b052133363..dda760b8fe4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
@@ -99,8 +99,9 @@ class AgentReadinessTest extends WC_Unit_Test_Case {

 		$report = $this->sut->get_report();

-		$this->assertSame( array( 'generated_at', 'products', 'available', 'hidden_from_catalog', 'unsupported_types', 'store_checks', 'declared', 'pages_best_seller', 'channels', 'checks', 'truncated', 'sales' ), array_keys( $report ) );
+		$this->assertSame( array( 'generated_at', 'products', 'available', 'hidden_from_catalog', 'unsupported_types', 'store_checks', 'declared', 'pages_best_seller', 'channels', 'checks', 'truncated', 'bestsellers_first', 'bestsellers_count', 'sales' ), array_keys( $report ) );
 		$this->assertFalse( $report['truncated'] );
+		$this->assertSame( 0, $report['bestsellers_count'] );
 		$this->assertSame( array( 'id', 'ok', 'blocks', 'group', 'level', 'name', 'label', 'why', 'fix', 'fix_url' ), array_keys( $report['store_checks'][0] ) );
 		$this->assertSame( array( 'chatgpt', 'google', 'copilot' ), array_keys( $report['channels'] ) );
 		$this->assertSame(
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
index 311fafe810a..8e31e452129 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
@@ -1688,6 +1688,30 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
 			$this->view()['overview']['based_on'],
 			'The AI tools card says it after its description'
 		);
+
+		$stored['bestsellers_first'] = true;
+		update_option( AgentReadiness::REPORT_OPTION, $stored );
+		$this->assertSame(
+			sprintf( 'Product checks covered %s of your 8,400 products: your bestsellers first, then the ones you updated most recently. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+			$this->view()['checked_note'],
+			'A scan that took bestsellers first says so'
+		);
+		$this->assertSame(
+			sprintf( 'Based on %s products: your bestsellers first, then the ones you changed most recently.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+			$this->view()['overview']['based_on']
+		);
+
+		$stored['bestsellers_count'] = ProductScan::PRODUCT_LIMIT;
+		update_option( AgentReadiness::REPORT_OPTION, $stored );
+		$this->assertSame(
+			sprintf( 'Product checks covered %s of your 8,400 products: your bestsellers. Store conditions covered your whole store. Product details, and some Search and discovery checks, still sample product pages.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+			$this->view()['checked_note'],
+			'A scan filled by bestsellers does not claim recently changed products were checked'
+		);
+		$this->assertSame(
+			sprintf( 'Based on your %s bestsellers.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+			$this->view()['overview']['based_on']
+		);
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
index f967fac11f5..0b919921ac6 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
@@ -52,15 +52,76 @@ class ProductSalesTest extends WC_Unit_Test_Case {
 		$this->assertIsArray( $sales );
 		$this->assertSame( 90, $sales['days'] );
 		$this->assertSame( 1, $sales['orders'], 'Only the completed order in the period counts' );
-		$this->assertEqualsWithDelta( 20.0, $sales['by_product'][ $mug->get_id() ] ?? 0.0, 0.01 );
 		$this->assertGreaterThan( 0.0, (float) $variant->get_price(), 'The variation has a price, so its sales show' );
-		$this->assertArrayHasKey( $variable->get_id(), $sales['by_product'], 'A variation counts toward its parent' );
-		$this->assertEqualsWithDelta( (float) $variant->get_price(), $sales['by_product'][ $variable->get_id() ], 0.01 );
-		$this->assertArrayNotHasKey( $variant->get_id(), $sales['by_product'] );
-		$this->assertEqualsWithDelta( (float) $variant->get_price(), $sales['by_variation'][ $variant->get_id() ] ?? 0.0, 0.01, 'The variation\'s own sales are kept too' );
-		$this->assertArrayNotHasKey( $mug->get_id(), $sales['by_variation'] );
-		$this->assertArrayNotHasKey( $vase->get_id(), $sales['by_product'], 'Cancelled and older orders are left out' );
 		$this->assertEqualsWithDelta( 20.0 + (float) $variant->get_price(), $sales['total'], 0.01 );
+		$this->assertArrayNotHasKey( 'top', $sales, 'The totals do not list best sellers; the scan asks for them only when it ranks' );
+		$this->assertEqualsCanonicalizing( array( $mug->get_id(), $variable->get_id() ), $this->sut->more_top_products( $sales['since'], 0, ProductSales::TOP_PRODUCTS ), 'A variation counts toward its parent; cancelled and older orders are left out' );
+
+		$some = $this->sut->for_products( array( $mug->get_id(), $variable->get_id(), $vase->get_id() ), $sales['since'] );
+
+		$this->assertEqualsWithDelta( 20.0, $some['by_product'][ $mug->get_id() ] ?? 0.0, 0.01 );
+		$this->assertEqualsWithDelta( (float) $variant->get_price(), $some['by_product'][ $variable->get_id() ] ?? 0.0, 0.01 );
+		$this->assertArrayNotHasKey( $variant->get_id(), $some['by_product'] );
+		$this->assertEqualsWithDelta( (float) $variant->get_price(), $some['by_variation'][ $variant->get_id() ] ?? 0.0, 0.01, 'The variation\'s own sales are kept too' );
+		$this->assertArrayNotHasKey( $mug->get_id(), $some['by_variation'] );
+		$this->assertArrayNotHasKey( $vase->get_id(), $some['by_product'] );
+	}
+
+	/**
+	 * @testdox The best sellers are listed with the most net sales first, leaving out a product refunded in full.
+	 */
+	public function test_last_days_lists_best_sellers_first(): void {
+		$mug    = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 10 ) );
+		$vase   = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 30 ) );
+		$lamp   = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 50 ) );
+		$unsold = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 90 ) );
+
+		$this->order( array( array( $mug, 1 ) ), OrderStatus::COMPLETED );
+		$this->order( array( array( $vase, 2 ) ), OrderStatus::COMPLETED );
+		$this->order( array( array( $mug, 1 ) ), OrderStatus::PROCESSING );
+		$order  = $this->order( array( array( $lamp, 1 ) ), OrderStatus::COMPLETED );
+		$items  = $order->get_items();
+		$item   = reset( $items );
+		$refund = wc_create_refund(
+			array(
+				'order_id'   => $order->get_id(),
+				'amount'     => 50,
+				'line_items' => array(
+					$item->get_id() => array(
+						'qty'          => 1,
+						'refund_total' => 50,
+					),
+				),
+			)
+		);
+		$this->assertInstanceOf( \WC_Order_Refund::class, $refund );
+		OrdersStatsDataStore::sync_order( $refund->get_id() );
+		ProductsDataStore::sync_order_products( $refund->get_id() );
+
+		$sales = $this->sut->last_days();
+
+		$top = $this->sut->more_top_products( $sales['since'], 0, ProductSales::TOP_PRODUCTS );
+		$this->assertSame( array( $vase->get_id(), $mug->get_id() ), $top, 'Vase 60, mug 20; the lamp nets to nothing and one product never sold' );
+		$this->assertNotContains( $unsold->get_id(), $top );
+		$this->assertEqualsWithDelta( 80.0, $sales['total'], 0.01 );
+		$this->assertSame( array( $mug->get_id() ), $this->sut->more_top_products( $sales['since'], 1, 1 ) );
+	}
+
+	/**
+	 * @testdox A deleted product keeps its revenue in the total and drops out of the best sellers.
+	 */
+	public function test_top_products_skip_a_deleted_product(): void {
+		$mug  = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 10 ) );
+		$lamp = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 40 ) );
+
+		$this->order( array( array( $mug, 1 ) ), OrderStatus::COMPLETED );
+		$this->order( array( array( $lamp, 1 ) ), OrderStatus::COMPLETED );
+		$lamp->delete( true );
+
+		$sales = $this->sut->last_days();
+
+		$this->assertSame( array( $mug->get_id() ), $this->sut->more_top_products( $sales['since'], 0, ProductSales::TOP_PRODUCTS ) );
+		$this->assertEqualsWithDelta( 50.0, $sales['total'], 0.01, 'The deleted product\'s revenue still counts' );
 	}

 	/**
@@ -89,7 +150,8 @@ class ProductSalesTest extends WC_Unit_Test_Case {

 		$sales = $this->sut->last_days();

-		$this->assertEqualsWithDelta( 10.0, $sales['by_product'][ $mug->get_id() ] ?? 0.0, 0.01, 'Two sold, one refunded' );
+		$this->assertEqualsWithDelta( 10.0, $sales['total'], 0.01, 'Two sold, one refunded' );
+		$this->assertEqualsWithDelta( 10.0, $this->sut->for_products( array( $mug->get_id() ), $sales['since'] )['by_product'][ $mug->get_id() ] ?? 0.0, 0.01 );
 		$this->assertSame( 1, $sales['orders'] );
 	}

@@ -210,7 +272,7 @@ class ProductSalesTest extends WC_Unit_Test_Case {
 			$sales = $this->sut->last_days();

 			$this->assertSame( 1, $sales['orders'], 'The older order is out, though its local date reads later than the UTC boundary' );
-			$this->assertEqualsWithDelta( 20.0, $sales['by_product'][ $mug->get_id() ] ?? 0.0, 0.01 );
+			$this->assertEqualsWithDelta( 20.0, $sales['total'], 0.01 );
 		} finally {
 			delete_option( 'timezone_string' );
 		}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
index 8d6694e02f1..2dac52f0f8e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
@@ -206,6 +206,101 @@ class ScheduledScanTest extends WC_Unit_Test_Case {
 		$this->assertCount( 1, $this->pending( ScheduledScan::DAILY_HOOK ) );
 	}

+	/**
+	 * @testdox The daily run is scheduled for the store's night slot: within a day, between 1:00 and 5:00 on the store's clock, at the same minute each time.
+	 */
+	public function test_daily_run_is_scheduled_at_night_in_site_time(): void {
+		try {
+			update_option( 'timezone_string', 'Pacific/Auckland' );
+
+			$this->sut->run();
+			$next = as_next_scheduled_action( ScheduledScan::DAILY_HOOK, array(), ScheduledScan::GROUP );
+
+			$this->assertIsInt( $next );
+			$this->assertSame( ScheduledScan::next_daily_run(), $next );
+			foreach ( array( '2026-11-25 10:00', '2026-11-25 23:30', '2026-11-26 00:30', '2026-11-26 04:59' ) as $local ) {
+				$now  = ( new \DateTimeImmutable( $local, wp_timezone() ) )->getTimestamp();
+				$slot = ScheduledScan::next_daily_run( $now );
+				$hour = (int) wp_date( 'G', $slot );
+				$this->assertGreaterThanOrEqual( ScheduledScan::NIGHT_FROM, $hour, $local );
+				$this->assertLessThan( ScheduledScan::NIGHT_TO, $hour, $local );
+				$this->assertGreaterThanOrEqual( $now + ScheduledScan::MIN_GAP, $slot, 'A check late at night is not followed by another within hours: ' . $local );
+				$this->assertLessThanOrEqual( $now + DAY_IN_SECONDS + ScheduledScan::MIN_GAP, $slot, $local );
+				$this->assertSame( wp_date( 'H:i', ScheduledScan::next_daily_run() ), wp_date( 'H:i', $slot ), 'The same minute each night' );
+			}
+		} finally {
+			delete_option( 'timezone_string' );
+		}
+	}
+
+	/**
+	 * @testdox A catalog over the limit lists its best sellers first, most sales first, then the newest changes; one that fits keeps the newest change first.
+	 */
+	public function test_catalog_over_the_limit_lists_best_sellers_first(): void {
+		$ids    = $this->create_products( 3 );
+		$hidden = WC_Helper_Product::create_simple_product();
+		$hidden->set_catalog_visibility( 'hidden' );
+		$hidden->save();
+		$by_change = ( new ProductScan() )->start();
+		$sellers   = array( $ids[1], $hidden->get_id(), $ids[0] );
+
+		$this->assertSame( $by_change, ( new ProductScan() )->start_best_sellers_first( $sellers ), 'Every product is checked, so the order stays' );
+
+		$recent = range( 900001, 900001 + ProductScan::PRODUCT_LIMIT );
+		$many   = static function ( $posts, $query ) use ( $recent ) {
+			return ProductScan::PRODUCT_LIMIT + 1 === (int) $query->get( 'posts_per_page' ) ? $recent : $posts;
+		};
+		add_filter( 'posts_pre_query', $many, 10, 2 );
+		try {
+			$scan   = new ProductScan();
+			$listed = $scan->start_best_sellers_first( $sellers );
+			$plain  = ( new ProductScan() )->start();
+			$unseen = new ProductScan();
+			$unseen->start_best_sellers_first( array( $hidden->get_id() ) );
+		} finally {
+			remove_filter( 'posts_pre_query', $many, 10 );
+		}
+
+		$this->assertTrue( $scan->truncated() );
+		$this->assertTrue( $scan->best_sellers_first() );
+		$this->assertSame( 2, $scan->bestsellers_count() );
+		$this->assertCount( ProductScan::PRODUCT_LIMIT, $listed );
+		$this->assertSame( array( $ids[1], $ids[0], 900001 ), array_slice( $listed, 0, 3 ), 'Best sellers in sales order, without the hidden one, then the newest changes' );
+		$this->assertSame( array_slice( $recent, 0, ProductScan::PRODUCT_LIMIT ), $plain, 'Without sales to rank by, the newest changes only' );
+		$this->assertFalse( $unseen->best_sellers_first(), 'No best seller the scan checks, so the list is the newest changes' );
+		$this->assertSame( 0, $unseen->bestsellers_count() );
+	}
+
+	/**
+	 * @testdox A full page of sellers the scan cannot check is followed by the next page, which then leads the list.
+	 */
+	public function test_next_seller_page_leads_when_the_first_page_is_ineligible(): void {
+		$seller = WC_Helper_Product::create_simple_product();
+		$recent = range( 900001, 900001 + ProductScan::PRODUCT_LIMIT );
+		$first  = range( 8000001, 8000001 + ProductScan::PRODUCT_LIMIT - 1 );
+		$many   = static function ( $posts, $query ) use ( $recent ) {
+			return ProductScan::PRODUCT_LIMIT + 1 === (int) $query->get( 'posts_per_page' ) ? $recent : $posts;
+		};
+		$offset = 0;
+		$more   = static function ( int $next_offset, int $limit ) use ( $seller, &$offset ): array {
+			unset( $limit );
+			$offset = $next_offset;
+			return array( $seller->get_id() );
+		};
+		add_filter( 'posts_pre_query', $many, 10, 2 );
+		try {
+			$scan   = new ProductScan();
+			$listed = $scan->start_best_sellers_first( $first, $more );
+		} finally {
+			remove_filter( 'posts_pre_query', $many, 10 );
+		}
+
+		$this->assertSame( ProductScan::PRODUCT_LIMIT, $offset );
+		$this->assertTrue( $scan->best_sellers_first() );
+		$this->assertSame( 1, $scan->bestsellers_count() );
+		$this->assertSame( array( $seller->get_id(), 900001 ), array_slice( $listed, 0, 2 ) );
+	}
+
 	/**
 	 * @testdox A run fetches the rules file before scanning, so the new rules shape the report.
 	 */