Commit 57a9330f1c3 for woocommerce
commit 57a9330f1c38f250221bea91a99652f64554e7f5
Author: Alba Rincón <albarin@users.noreply.github.com>
Date: Thu Mar 26 15:26:38 2026 +0100
Performance: prime product thumbnail caches on archive pages (#63877)
* Performance: prime product thumbnail caches on archive pages
* Add changefile(s) from automation for the following project(s): woocommerce
* Remove extra blank line
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/63877-fix-63858-prime-product-thumbnail-caches b/plugins/woocommerce/changelog/63877-fix-63858-prime-product-thumbnail-caches
new file mode 100644
index 00000000000..48510771f71
--- /dev/null
+++ b/plugins/woocommerce/changelog/63877-fix-63858-prime-product-thumbnail-caches
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Prime featured image caches on product archive pages to reduce SQL queries during rendering.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-query.php b/plugins/woocommerce/includes/class-wc-query.php
index 4aaefff1367..756e85ed491 100644
--- a/plugins/woocommerce/includes/class-wc-query.php
+++ b/plugins/woocommerce/includes/class-wc-query.php
@@ -436,6 +436,22 @@ class WC_Query {
return $posts;
}
+ /**
+ * Prime featured image caches for product queries to avoid individual
+ * queries during rendering.
+ *
+ * @since 10.8.0
+ *
+ * @param array $posts Posts from WP Query.
+ * @param WP_Query $query Current query.
+ * @return array
+ */
+ public function prime_thumbnail_caches( $posts, $query ) {
+ if ( 'product_query' === $query->get( 'wc_query' ) ) {
+ update_post_thumbnail_cache( $query );
+ }
+ return $posts;
+ }
/**
* Pre_get_posts above may adjust the main query to add WooCommerce logic. When this query is done, we need to ensure
@@ -539,6 +555,7 @@ class WC_Query {
// Additional hooks to change WP Query.
add_filter( 'posts_clauses', array( $this, 'product_query_post_clauses' ), 10, 2 );
add_filter( 'the_posts', array( $this, 'handle_get_posts' ), 10, 2 );
+ add_filter( 'the_posts', array( $this, 'prime_thumbnail_caches' ), 10, 2 );
do_action( 'woocommerce_product_query', $q, $this );
}