Commit c569020e11 for woocommerce
commit c569020e11c1ac920c98b7e7da0c312953f2a000
Author: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
Date: Tue Dec 9 17:47:47 2025 +0900
Add scheduled import for new installations and enable `analytics-scheduled-import` feature flag (#62331)
* Add default scheduled import option for new installations
- Introduced a new method to enable analytics scheduled import as the default setting for newly installed WooCommerce instances.
- Added unit tests to verify that the scheduled import option is set correctly and does not overwrite existing values.
These changes ensure a smoother onboarding experience for new users by defaulting to the scheduled import feature.
* Add changelog and enable feature flag
* Fix type
diff --git a/plugins/woocommerce/changelog/wooa7s-843-rename-option-to-woocommerce_analytics_scheduled_import-new b/plugins/woocommerce/changelog/wooa7s-843-rename-option-to-woocommerce_analytics_scheduled_import-new
new file mode 100644
index 0000000000..f1f9925b11
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooa7s-843-rename-option-to-woocommerce_analytics_scheduled_import-new
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add default scheduled import option for new installations
diff --git a/plugins/woocommerce/client/admin/config/core.json b/plugins/woocommerce/client/admin/config/core.json
index cb00d67250..83b2902f3b 100644
--- a/plugins/woocommerce/client/admin/config/core.json
+++ b/plugins/woocommerce/client/admin/config/core.json
@@ -2,7 +2,7 @@
"features": {
"activity-panels": true,
"analytics": true,
- "analytics-scheduled-import": false,
+ "analytics-scheduled-import": true,
"product-block-editor": true,
"product-data-views": false,
"experimental-blocks": false,
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index 034d481c85..a2ac1e4946 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -355,6 +355,7 @@ class WC_Install {
add_action( 'woocommerce_newly_installed', array( __CLASS__, 'add_coming_soon_option' ), 20 );
add_action( 'woocommerce_newly_installed', array( __CLASS__, 'enable_email_improvements_for_newly_installed' ), 20 );
add_action( 'woocommerce_newly_installed', array( __CLASS__, 'enable_customer_stock_notifications_signups' ), 20 );
+ add_action( 'woocommerce_newly_installed', array( __CLASS__, 'enable_analytics_scheduled_import' ), 20 );
add_action( 'woocommerce_updated', array( __CLASS__, 'enable_email_improvements_for_existing_merchants' ), 20 );
add_action( 'woocommerce_run_update_callback', array( __CLASS__, 'run_update_callback' ) );
add_action( 'woocommerce_update_db_to_current_version', array( __CLASS__, 'update_db_version' ) );
@@ -1179,6 +1180,21 @@ class WC_Install {
update_option( 'woocommerce_back_in_stock_allow_signups', 'yes' );
}
+ /**
+ * Set scheduled import mode as the default for new installations.
+ *
+ * Uses add_option() which only sets the option if it doesn't already exist.
+ * This ensures existing installations are not affected.
+ *
+ * @since 10.5.0
+ *
+ * @return void
+ */
+ public static function enable_analytics_scheduled_import(): void {
+ // add_option only sets if option doesn't exist, returns false if it already exists.
+ add_option( 'woocommerce_analytics_scheduled_import', 'yes' );
+ }
+
/**
* Enable email improvements by default for existing shops if conditions are met.
*
@@ -2782,7 +2798,7 @@ $stock_notifications_table_schema;
* @return string The content for the page
*/
private static function get_refunds_return_policy_page_content() {
- return <<<EOT
+ return <<<'EOT'
<!-- wp:paragraph -->
<p><b>This is a sample page.</b></p>
<!-- /wp:paragraph -->
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/install.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/install.php
index ceb86cd2a4..37d75aa9af 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/install.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/install.php
@@ -191,6 +191,38 @@ class WC_Admin_Tests_Install extends WP_UnitTestCase {
$this->assertEquals( get_option( WC_Install::INITIAL_INSTALLED_VERSION ), self::$initial_installed_version_number );
}
+ /**
+ * Test scheduled import is set as default for new installations.
+ *
+ * @return void
+ */
+ public function test_enable_analytics_scheduled_import_for_new_installation() {
+ // Ensure the option doesn't exist before testing.
+ delete_option( 'woocommerce_analytics_scheduled_import' );
+
+ // Call the method to set the default.
+ WC_Install::enable_analytics_scheduled_import();
+
+ // Verify the option was set to 'yes'.
+ $this->assertEquals( 'yes', get_option( 'woocommerce_analytics_scheduled_import' ) );
+ }
+
+ /**
+ * Test scheduled import option is not overwritten if already exists.
+ *
+ * @return void
+ */
+ public function test_enable_analytics_scheduled_import_preserves_existing_value() {
+ // Set the option to 'no' to simulate an existing installation with the option already set.
+ update_option( 'woocommerce_analytics_scheduled_import', 'no' );
+
+ // Call the method which should not overwrite the existing value.
+ WC_Install::enable_analytics_scheduled_import();
+
+ // Verify the option remains 'no' (not overwritten).
+ $this->assertEquals( 'no', get_option( 'woocommerce_analytics_scheduled_import' ) );
+ }
+
/**
* Test migrate_options();
* @return void