Commit bf892e11c4 for woocommerce

commit bf892e11c4fe84325da7abfc5491d4be7586ba61
Author: Alba Rincón <albarin@users.noreply.github.com>
Date:   Tue Nov 25 16:00:02 2025 +0100

    Add db update to autoload frequently used options (#62036)

    * Add db update to autoload frequently used options.

    * Remove options

    * Move feature options and fix sql query

    * Add changelog

    * Set autoload to auto

    * Set autoload to true for new feature flags

    * Use the correct feature name

diff --git a/plugins/woocommerce/changelog/fix-61855-autoload-options b/plugins/woocommerce/changelog/fix-61855-autoload-options
new file mode 100644
index 0000000000..2cc7afffc1
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-61855-autoload-options
@@ -0,0 +1,4 @@
+Significance: minor
+Type: update
+
+Add db update to autoload frequently used options
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index 04b48e0bf9..c8d094890c 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -315,6 +315,7 @@ class WC_Install {
 		),
 		'10.5.0' => array(
 			'wc_update_1050_migrate_brand_permalink_setting',
+			'wc_update_1050_enable_autoload_options',
 		),
 	);

diff --git a/plugins/woocommerce/includes/wc-update-functions.php b/plugins/woocommerce/includes/wc-update-functions.php
index 0da5d91ce9..7226d9b3e0 100644
--- a/plugins/woocommerce/includes/wc-update-functions.php
+++ b/plugins/woocommerce/includes/wc-update-functions.php
@@ -29,6 +29,7 @@ use Automattic\WooCommerce\Internal\AssignDefaultCategory;
 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
 use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
 use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
+use Automattic\WooCommerce\Internal\Features\FeaturesController;
 use Automattic\WooCommerce\Internal\ProductAttributesLookup\DataRegenerator;
 use Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore;
 use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories;
@@ -3159,3 +3160,59 @@ function wc_update_1050_migrate_brand_permalink_setting() {
 	$slug = trailingslashit( $shop_slug ) . __( 'brand', 'woocommerce' );
 	update_option( 'woocommerce_brand_permalink', $slug );
 }
+
+/**
+ * Autoload frequently used options for performance improvements (see https://github.com/woocommerce/woocommerce/issues/61855)
+ *
+ * `$autoload_options` are frequently used options that may already be in the db but with `autoload = off`.
+ * `$feature_options` are frequently used feature flag options that are not stored in the db.
+ *
+ * @return void
+ */
+function wc_update_1050_enable_autoload_options() {
+	global $wpdb;
+
+	$autoload_options = array(
+		// Page ID options with autoload `off` in the db.
+		'woocommerce_myaccount_page_id',
+		'woocommerce_cart_page_id',
+		'woocommerce_checkout_page_id',
+		'woocommerce_terms_page_id',
+		// Feature status options with autoload `off` in the db.
+		'woocommerce_show_marketplace_suggestions',
+		'woocommerce_enable_delayed_account_creation',
+		'wc_feature_woocommerce_brands_enabled',
+		'wc_connect_taxes_enabled',
+		'woocommerce_logs_logging_enabled',
+		'woocommerce_email_improvements_existing_store_enabled',
+		'woocommerce_custom_orders_table_data_sync_enabled',
+	);
+
+	$feature_options = array(
+		'fulfillments'         => 'woocommerce_feature_fulfillments_enabled',
+		'marketplace'          => 'woocommerce_feature_marketplace_enabled',
+		'push_notifications'   => 'woocommerce_feature_push_notifications_enabled',
+		'agentic_checkout'     => 'woocommerce_feature_agentic_checkout_enabled',
+		'cart_checkout_blocks' => 'woocommerce_feature_cart_checkout_blocks_enabled',
+	);
+
+	$features_controller = wc_get_container()->get( FeaturesController::class );
+
+	foreach ( $feature_options as $key => $option ) {
+		if ( false === get_option( $option, false ) ) {
+			add_option( $option, wc_bool_to_string( $features_controller->feature_is_enabled( $key ) ), '', true );
+		} else {
+			$autoload_options[] = $option;
+		}
+	}
+
+	$placeholders = implode( ', ', array_fill( 0, count( $autoload_options ), '%s' ) );
+
+	$wpdb->query(
+		$wpdb->prepare(
+		// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+			"UPDATE {$wpdb->options} SET autoload = 'on' WHERE option_name IN ($placeholders)",
+			...$autoload_options
+		)
+	);
+}
diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
index 44d7e649c6..2b880d3f01 100644
--- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php
+++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
@@ -806,7 +806,7 @@ class FeaturesController {
 			return false;
 		}

-		return update_option( $this->feature_enable_option_name( $feature_id ), $enable ? 'yes' : 'no' );
+		return update_option( $this->feature_enable_option_name( $feature_id ), $enable ? 'yes' : 'no', 'on' );
 	}

 	/**