Commit 6c248c01bc1 for woocommerce
commit 6c248c01bc16f9852ce67823eb427842a5e7eea5
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date: Thu Nov 12 10:35:03 2026 +0100
[Performance] Autoload frequently used HPOS and catalog display options (#70409)
diff --git a/plugins/woocommerce/changelog/performance-hpos-and-catalog-options-autoload b/plugins/woocommerce/changelog/performance-hpos-and-catalog-options-autoload
new file mode 100644
index 00000000000..760ffbf7350
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-hpos-and-catalog-options-autoload
@@ -0,0 +1,4 @@
+Significance: minor
+Type: performance
+
+Autoload frequently used HPOS and catalog display options.
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index b39d48124e9..981c25b19d7 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -1282,11 +1282,11 @@ class WC_Install {
foreach ( $subsections as $subsection ) {
foreach ( $section->get_settings( $subsection ) as $value ) {
- if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
- $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
- $skip_initial_save = isset( $value['skip_initial_save'] ) ? (bool) $value['skip_initial_save'] : false;
+ if ( isset( $value['default'], $value['id'] ) ) {
+ $autoload = (bool) ( $value['autoload'] ?? true );
+ $skip_initial_save = (bool) ( $value['skip_initial_save'] ?? false );
if ( ! $skip_initial_save ) {
- add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
+ add_option( $value['id'], $value['default'], '', $autoload );
}
}
}
@@ -1294,10 +1294,13 @@ class WC_Install {
}
// Define other defaults if not in setting screens.
- add_option( 'woocommerce_single_image_width', '600', '', 'yes' );
- add_option( 'woocommerce_thumbnail_image_width', '300', '', 'yes' );
- add_option( 'woocommerce_checkout_highlight_required_fields', 'yes', '', 'yes' );
- add_option( 'woocommerce_demo_store', 'no', '', 'no' );
+ add_option( 'woocommerce_single_image_width', '600', '', true );
+ add_option( 'woocommerce_thumbnail_image_width', '300', '', true );
+ add_option( 'woocommerce_checkout_highlight_required_fields', 'yes', '', true );
+ add_option( 'woocommerce_demo_store', 'no', '', false );
+ add_option( 'woocommerce_catalog_columns', '4', '', true );
+ add_option( 'woocommerce_catalog_rows', '4', '', true );
+ add_option( 'woocommerce_default_catalog_orderby', 'menu_order', '', true );
if ( self::is_new_install() ) {
// Define initial tax classes.
diff --git a/plugins/woocommerce/includes/class-wc-query.php b/plugins/woocommerce/includes/class-wc-query.php
index c545de628de..93f3249b0d3 100644
--- a/plugins/woocommerce/includes/class-wc-query.php
+++ b/plugins/woocommerce/includes/class-wc-query.php
@@ -612,15 +612,6 @@ class WC_Query {
* @param WP_Query $q Query instance.
*/
public function product_query( $q ) {
- // Prime caches to reduce future queries.
- wp_prime_option_caches(
- array(
- 'woocommerce_default_catalog_orderby',
- 'woocommerce_catalog_columns',
- 'woocommerce_catalog_rows',
- )
- );
-
if ( ! is_feed() ) {
$ordering = $this->get_catalog_ordering_args();
$q->set( 'orderby', $ordering['orderby'] );
diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php
index 7305e8e0663..a4bd5bcc307 100644
--- a/plugins/woocommerce/includes/wc-template-functions.php
+++ b/plugins/woocommerce/includes/wc-template-functions.php
@@ -438,10 +438,10 @@ function wc_get_default_products_per_row() {
if ( $min_columns && $columns < $min_columns ) {
$columns = $min_columns;
- update_option( 'woocommerce_catalog_columns', $columns );
+ update_option( 'woocommerce_catalog_columns', $columns, true );
} elseif ( $max_columns && $columns > $max_columns ) {
$columns = $max_columns;
- update_option( 'woocommerce_catalog_columns', $columns );
+ update_option( 'woocommerce_catalog_columns', $columns, true );
}
if ( has_filter( 'loop_shop_columns' ) ) { // Legacy filter handling.
@@ -467,10 +467,10 @@ function wc_get_default_product_rows_per_page() {
if ( $min_rows && $rows < $min_rows ) {
$rows = $min_rows;
- update_option( 'woocommerce_catalog_rows', $rows );
+ update_option( 'woocommerce_catalog_rows', $rows, true );
} elseif ( $max_rows && $rows > $max_rows ) {
$rows = $max_rows;
- update_option( 'woocommerce_catalog_rows', $rows );
+ update_option( 'woocommerce_catalog_rows', $rows, true );
}
return $rows;
@@ -486,11 +486,11 @@ function wc_reset_product_grid_settings() {
$product_grid = wc_get_theme_support( 'product_grid' );
if ( ! empty( $product_grid['default_rows'] ) ) {
- update_option( 'woocommerce_catalog_rows', absint( $product_grid['default_rows'] ) );
+ update_option( 'woocommerce_catalog_rows', absint( $product_grid['default_rows'] ), true );
}
if ( ! empty( $product_grid['default_columns'] ) ) {
- update_option( 'woocommerce_catalog_columns', absint( $product_grid['default_columns'] ) );
+ update_option( 'woocommerce_catalog_columns', absint( $product_grid['default_columns'] ), true );
}
wp_cache_flush(); // Flush any caches which could impact settings or templates.
diff --git a/plugins/woocommerce/includes/wc-update-functions.php b/plugins/woocommerce/includes/wc-update-functions.php
index 22df81362fb..effde8e02b8 100644
--- a/plugins/woocommerce/includes/wc-update-functions.php
+++ b/plugins/woocommerce/includes/wc-update-functions.php
@@ -4227,7 +4227,7 @@ function wc_update_1130_backfill_order_stats_payment_method() {
}
/**
- * Re-enable autoloading for options whose settings definitions reverted it on save after the 10.5.0 migration.
+ * Autoload frequently read options that existing stores may still have as autoload off.
*
* @since 11.4.0
*/
@@ -4241,6 +4241,11 @@ function wc_update_1140_re_enable_autoload_options(): void {
'woocommerce_show_marketplace_suggestions' => true,
'woocommerce_enable_delayed_account_creation' => true,
'woocommerce_logs_logging_enabled' => true,
+ 'woocommerce_catalog_columns' => true,
+ 'woocommerce_catalog_rows' => true,
+ 'woocommerce_default_catalog_orderby' => true,
+ 'woocommerce_custom_orders_table_data_sync_enabled' => true,
+ 'woocommerce_custom_orders_table_background_sync_mode' => true,
)
);
}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 601b89d2225..b7a6bd2044f 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -11862,12 +11862,6 @@ parameters:
count: 4
path: includes/class-wc-install.php
- -
- message: '#^Parameter \#4 \$autoload of function add_option expects bool\|null, string given\.$#'
- identifier: argument.type
- count: 5
- path: includes/class-wc-install.php
-
-
message: '#^Parameter \#5 \$post_parent of function wc_create_page expects int, int\|string given\.$#'
identifier: argument.type