Commit 185d9c177c for woocommerce
commit 185d9c177c2337b1c2102f2f41a590908534267c
Author: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
Date: Tue Dec 9 17:17:28 2025 +0900
Rename the option from `woocommerce_analytics_immediate_import` to `woocommerce_analytics_scheduled_import` (#62303)
* Refactor analytics import settings to use scheduled import
- Rename settings and related variables from immediate to scheduled import.
- Update conditional logic in components and API to reflect the new scheduled import option.
- Adjust tests to ensure they align with the new scheduled import functionality.
These changes enhance the clarity and functionality of the analytics import process, promoting the use of scheduled imports as the recommended approach.
* Fix tests
* Fix tests
* Fix lint
diff --git a/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/import-status-bar.tsx b/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/import-status-bar.tsx
index 38e708a3b6..2a597f92bf 100644
--- a/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/import-status-bar.tsx
+++ b/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/import-status-bar.tsx
@@ -33,15 +33,15 @@ export function ImportStatusBar(): JSX.Element | null {
'wcAdminSettings',
] ) as unknown as {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'yes' | 'no';
+ woocommerce_analytics_scheduled_import: 'yes' | 'no';
};
};
- // Don't render if immediate import is enabled
+ // Don't render if scheduled import is disabled (immediate mode)
// Use the value from the settings hook rather than the status object; accessing settings is faster because they are preloaded.
if (
- ! wcAdminSettings?.woocommerce_analytics_immediate_import ||
- wcAdminSettings.woocommerce_analytics_immediate_import === 'yes'
+ ! wcAdminSettings?.woocommerce_analytics_scheduled_import ||
+ wcAdminSettings.woocommerce_analytics_scheduled_import === 'no'
) {
return null;
}
diff --git a/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/test/import-status-bar.test.tsx b/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/test/import-status-bar.test.tsx
index 793d652b65..f9c87966e8 100644
--- a/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/test/import-status-bar.test.tsx
+++ b/plugins/woocommerce/client/admin/client/analytics/components/import-status-bar/test/import-status-bar.test.tsx
@@ -31,7 +31,7 @@ jest.mock( '@woocommerce/data', () => ( {
...jest.requireActual( '@woocommerce/data' ),
useSettings: jest.fn().mockImplementation( () => ( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'no',
+ woocommerce_analytics_scheduled_import: 'yes',
},
} ) ),
} ) );
@@ -58,7 +58,7 @@ describe( 'ImportStatusBar', () => {
} );
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'no',
+ woocommerce_analytics_scheduled_import: 'yes',
},
} as unknown as ReturnType< typeof useSettings > );
} );
@@ -82,7 +82,7 @@ describe( 'ImportStatusBar', () => {
it( 'should not render when mode is immediate', () => {
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'yes',
+ woocommerce_analytics_scheduled_import: 'no',
},
} as unknown as ReturnType< typeof useSettings > );
// Mock useImportStatus to avoid destructuring error even though component returns early
diff --git a/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/index.tsx b/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/index.tsx
index 22cb447e2a..9ffbc01533 100644
--- a/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/index.tsx
+++ b/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/index.tsx
@@ -8,7 +8,7 @@ import { createInterpolateElement } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { recordEvent } from '@woocommerce/tracks';
-const IMMEDIATE_IMPORT_OPTION = 'woocommerce_analytics_immediate_import';
+const SCHEDULED_IMPORT_OPTION = 'woocommerce_analytics_scheduled_import';
export default function ScheduledUpdatesPromotionNotice() {
// Get settings to check option value (hooks must be called before early returns)
@@ -24,9 +24,9 @@ export default function ScheduledUpdatesPromotionNotice() {
return null;
}
- const optionValue = wcAdminSettings?.[ IMMEDIATE_IMPORT_OPTION ];
+ const optionValue = wcAdminSettings?.[ SCHEDULED_IMPORT_OPTION ];
// No need to show notice if option is already set.
- if ( optionValue === 'no' || optionValue === 'yes' ) {
+ if ( optionValue === 'yes' || optionValue === 'no' ) {
return null;
}
diff --git a/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/test/index.tsx b/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/test/index.tsx
index 66ce3d6256..35dc77bc34 100644
--- a/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/test/index.tsx
+++ b/plugins/woocommerce/client/admin/client/analytics/components/scheduled-updates-promotion-notice/test/index.tsx
@@ -113,10 +113,10 @@ describe( 'ScheduledUpdatesPromotionNotice', () => {
} );
describe( 'Option value check', () => {
- test( 'should not render when option is set to "yes"', () => {
+ test( 'should not render when option is set to "no"', () => {
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'yes',
+ woocommerce_analytics_scheduled_import: 'no',
},
} as unknown as ReturnType< typeof useSettings > );
@@ -125,10 +125,10 @@ describe( 'ScheduledUpdatesPromotionNotice', () => {
expect( container.firstChild ).toBeNull();
} );
- test( 'should not render when option is set to "no"', () => {
+ test( 'should not render when option is set to "yes"', () => {
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'no',
+ woocommerce_analytics_scheduled_import: 'yes',
},
} as unknown as ReturnType< typeof useSettings > );
@@ -161,7 +161,7 @@ describe( 'ScheduledUpdatesPromotionNotice', () => {
test( 'should render when option is null', () => {
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: null,
+ woocommerce_analytics_scheduled_import: null,
},
} as unknown as ReturnType< typeof useSettings > );
@@ -383,7 +383,7 @@ describe( 'ScheduledUpdatesPromotionNotice', () => {
mockUseSettings.mockReturnValue( {
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'yes',
+ woocommerce_analytics_scheduled_import: 'no',
},
} as unknown as ReturnType< typeof useSettings > );
diff --git a/plugins/woocommerce/client/admin/client/analytics/settings/config.js b/plugins/woocommerce/client/admin/client/analytics/settings/config.js
index 465742ab87..1498ab45f4 100644
--- a/plugins/woocommerce/client/admin/client/analytics/settings/config.js
+++ b/plugins/woocommerce/client/admin/client/analytics/settings/config.js
@@ -23,8 +23,8 @@ export const DEFAULT_ORDER_STATUSES = [
'on-hold',
];
export const DEFAULT_DATE_RANGE = 'period=month&compare=previous_year';
-export const IMMEDIATE_IMPORT_SETTING_NAME =
- 'woocommerce_analytics_immediate_import';
+export const SCHEDULED_IMPORT_SETTING_NAME =
+ 'woocommerce_analytics_scheduled_import';
const filteredOrderStatuses = Object.keys( ORDER_STATUSES )
.filter( ( status ) => status !== 'refunded' )
@@ -162,14 +162,14 @@ if ( !! window.wcAdminFeatures?.[ 'analytics-scheduled-import' ] ) {
__( '12 hours', 'woocommerce' ) // Default value for the import interval.
);
- baseConfig[ IMMEDIATE_IMPORT_SETTING_NAME ] = {
- name: IMMEDIATE_IMPORT_SETTING_NAME,
+ baseConfig[ SCHEDULED_IMPORT_SETTING_NAME ] = {
+ name: SCHEDULED_IMPORT_SETTING_NAME,
label: __( 'Updates:', 'woocommerce' ),
inputType: 'radio',
options: [
{
label: __( 'Scheduled (recommended)', 'woocommerce' ),
- value: 'no',
+ value: 'yes',
description: sprintf(
/* translators: %s: import interval, e.g. "12 hours" */
__(
@@ -181,7 +181,7 @@ if ( !! window.wcAdminFeatures?.[ 'analytics-scheduled-import' ] ) {
},
{
label: __( 'Immediately', 'woocommerce' ),
- value: 'yes',
+ value: 'no',
description: __(
'Updates as soon as new data is available. May slow busy stores.',
'woocommerce'
@@ -189,10 +189,10 @@ if ( !! window.wcAdminFeatures?.[ 'analytics-scheduled-import' ] ) {
},
],
// This default value is primarily used when users click "Reset defaults" for settings.
- // We set 'no' (Scheduled) as the default for new installs, since it is the recommended, lowest-impact option.
- // Note: The PHP backend defaults to 'yes' (Immediate) to preserve legacy behavior for existing stores and avoid disrupting current site operations.
+ // We set 'yes' (Scheduled) as the default for new installs, since it is the recommended, lowest-impact option.
+ // Note: The PHP backend defaults to 'no' (Immediate) to preserve legacy behavior for existing stores and avoid disrupting current site operations.
// This intentional difference ensures new stores use the best-practice default, while existing stores are not affected by updates.
- defaultValue: 'no',
+ defaultValue: 'yes',
};
}
diff --git a/plugins/woocommerce/client/admin/client/analytics/settings/index.js b/plugins/woocommerce/client/admin/client/analytics/settings/index.js
index e73c51d822..ec5616f30f 100644
--- a/plugins/woocommerce/client/admin/client/analytics/settings/index.js
+++ b/plugins/woocommerce/client/admin/client/analytics/settings/index.js
@@ -14,7 +14,7 @@ import { recordEvent } from '@woocommerce/tracks';
* Internal dependencies
*/
import './index.scss';
-import { config, IMMEDIATE_IMPORT_SETTING_NAME } from './config';
+import { config, SCHEDULED_IMPORT_SETTING_NAME } from './config';
import Setting from './setting';
import HistoricalData from './historical-data';
import { ImportModeConfirmationModal } from './import-mode-confirmation-modal';
@@ -123,10 +123,10 @@ const Settings = ( { createNotice, query } ) => {
// Intercept import mode change from scheduled to immediate
if (
- name === IMMEDIATE_IMPORT_SETTING_NAME &&
- config[ IMMEDIATE_IMPORT_SETTING_NAME ] &&
- wcAdminSettings[ name ] === 'no' &&
- value === 'yes'
+ name === SCHEDULED_IMPORT_SETTING_NAME &&
+ config[ SCHEDULED_IMPORT_SETTING_NAME ] &&
+ wcAdminSettings[ name ] === 'yes' &&
+ value === 'no'
) {
setPendingImportModeChange( { name, value } );
setIsImportModeModalOpen( true );
@@ -166,6 +166,18 @@ const Settings = ( { createNotice, query } ) => {
setPendingImportModeChange( null );
};
+ const getSettingValue = ( setting ) => {
+ if (
+ setting === SCHEDULED_IMPORT_SETTING_NAME &&
+ ! wcAdminSettings[ setting ]
+ ) {
+ // If scheduled import setting is not set, return 'no' to show the immediate import option by default
+ return 'no';
+ }
+
+ return wcAdminSettings[ setting ];
+ };
+
return (
<Fragment>
<SectionHeader
@@ -175,7 +187,7 @@ const Settings = ( { createNotice, query } ) => {
{ Object.keys( config ).map( ( setting ) => (
<Setting
handleChange={ handleInputChange }
- value={ wcAdminSettings[ setting ] }
+ value={ getSettingValue( setting ) }
key={ setting }
name={ setting }
{ ...config[ setting ] }
@@ -201,7 +213,7 @@ const Settings = ( { createNotice, query } ) => {
) : (
<HistoricalData createNotice={ createNotice } />
) }
- { config[ IMMEDIATE_IMPORT_SETTING_NAME ] && (
+ { config[ SCHEDULED_IMPORT_SETTING_NAME ] && (
<ImportModeConfirmationModal
isOpen={ isImportModeModalOpen }
onClose={ handleImportModeCancel }
diff --git a/plugins/woocommerce/client/admin/client/analytics/settings/test/index.test.js b/plugins/woocommerce/client/admin/client/analytics/settings/test/index.test.js
index 9d2f4c0af4..10d99c083b 100644
--- a/plugins/woocommerce/client/admin/client/analytics/settings/test/index.test.js
+++ b/plugins/woocommerce/client/admin/client/analytics/settings/test/index.test.js
@@ -8,7 +8,7 @@ import { useSettings } from '@woocommerce/data';
* Internal dependencies
*/
import Settings from '../index';
-import { IMMEDIATE_IMPORT_SETTING_NAME } from '../config';
+import { SCHEDULED_IMPORT_SETTING_NAME } from '../config';
// Mock dependencies.
jest.mock( '@woocommerce/data', () => ( {
@@ -26,26 +26,26 @@ window.wcAdminFeatures = {
jest.mock( '../config', () => ( {
config: {
- woocommerce_analytics_immediate_import: {
- name: 'woocommerce_analytics_immediate_import',
+ woocommerce_analytics_scheduled_import: {
+ name: 'woocommerce_analytics_scheduled_import',
label: 'Updates:',
inputType: 'radio',
options: [
{
label: 'Scheduled (recommended)',
- value: 'no',
+ value: 'yes',
description: 'Updates automatically every 12 hours.',
},
{
label: 'Immediately',
- value: 'yes',
+ value: 'no',
description: 'Updates as soon as new data is available.',
},
],
- defaultValue: 'no',
+ defaultValue: 'yes',
},
},
- IMMEDIATE_IMPORT_SETTING_NAME: 'woocommerce_analytics_immediate_import',
+ SCHEDULED_IMPORT_SETTING_NAME: 'woocommerce_analytics_scheduled_import',
} ) );
jest.mock( '../historical-data', () => ( {
@@ -68,7 +68,7 @@ describe( 'Settings - Import Mode Modal', () => {
updateAndPersistSettings: jest.fn(),
updateSettings: mockUpdateSettings,
wcAdminSettings: {
- [ IMMEDIATE_IMPORT_SETTING_NAME ]: 'no',
+ [ SCHEDULED_IMPORT_SETTING_NAME ]: 'yes',
},
} );
@@ -168,7 +168,7 @@ describe( 'Settings - Import Mode Modal', () => {
// Setting should be updated.
expect( mockUpdateSettings ).toHaveBeenCalledWith( 'wcAdminSettings', {
- woocommerce_analytics_immediate_import: 'yes',
+ woocommerce_analytics_scheduled_import: 'no',
} );
} );
@@ -182,7 +182,7 @@ describe( 'Settings - Import Mode Modal', () => {
updateAndPersistSettings: jest.fn(),
updateSettings: mockUpdateSettings,
wcAdminSettings: {
- woocommerce_analytics_immediate_import: 'yes',
+ woocommerce_analytics_scheduled_import: 'no',
},
} );
@@ -199,7 +199,7 @@ describe( 'Settings - Import Mode Modal', () => {
// Setting should be updated immediately.
expect( mockUpdateSettings ).toHaveBeenCalledWith( 'wcAdminSettings', {
- woocommerce_analytics_immediate_import: 'no',
+ woocommerce_analytics_scheduled_import: 'yes',
} );
} );
} );
diff --git a/plugins/woocommerce/src/Admin/API/AnalyticsImports.php b/plugins/woocommerce/src/Admin/API/AnalyticsImports.php
index bd0c2b64e6..29af57da62 100644
--- a/plugins/woocommerce/src/Admin/API/AnalyticsImports.php
+++ b/plugins/woocommerce/src/Admin/API/AnalyticsImports.php
@@ -92,8 +92,8 @@ class AnalyticsImports extends \WC_REST_Data_Controller {
* @return \WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_status( $request ) {
- $is_immediate_mode = $this->is_immediate_import_enabled();
- $mode = $is_immediate_mode ? 'immediate' : 'scheduled';
+ $is_scheduled_mode = $this->is_scheduled_import_enabled();
+ $mode = $is_scheduled_mode ? 'scheduled' : 'immediate';
$response = array(
'mode' => $mode,
@@ -103,7 +103,7 @@ class AnalyticsImports extends \WC_REST_Data_Controller {
);
// For scheduled mode, populate additional fields.
- if ( ! $is_immediate_mode ) {
+ if ( $is_scheduled_mode ) {
$last_processed_gmt = get_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION, null );
$response['last_processed_date'] = ( is_string( $last_processed_gmt ) && $last_processed_gmt ) ? get_date_from_gmt( $last_processed_gmt, 'Y-m-d H:i:s' ) : null;
$response['next_scheduled'] = $this->get_next_scheduled_time();
@@ -120,10 +120,10 @@ class AnalyticsImports extends \WC_REST_Data_Controller {
* @return \WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function trigger_import( $request ) {
- $is_immediate_mode = $this->is_immediate_import_enabled();
+ $is_scheduled_mode = $this->is_scheduled_import_enabled();
// Return error if in immediate mode.
- if ( $is_immediate_mode ) {
+ if ( ! $is_scheduled_mode ) {
return new WP_Error(
'woocommerce_rest_analytics_import_immediate_mode',
__( 'Manual import is not available in immediate mode. Imports happen automatically.', 'woocommerce' ),
@@ -162,12 +162,12 @@ class AnalyticsImports extends \WC_REST_Data_Controller {
}
/**
- * Check if immediate import is enabled.
+ * Check if scheduled import is enabled.
*
* @return bool
*/
- private function is_immediate_import_enabled() {
- return 'no' !== get_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, OrdersScheduler::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE );
+ private function is_scheduled_import_enabled() {
+ return 'yes' === get_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, OrdersScheduler::SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE );
}
/**
diff --git a/plugins/woocommerce/src/Internal/Admin/Notes/ScheduledUpdatesPromotion.php b/plugins/woocommerce/src/Internal/Admin/Notes/ScheduledUpdatesPromotion.php
index 2c0564459d..e4b17230b9 100644
--- a/plugins/woocommerce/src/Internal/Admin/Notes/ScheduledUpdatesPromotion.php
+++ b/plugins/woocommerce/src/Internal/Admin/Notes/ScheduledUpdatesPromotion.php
@@ -34,7 +34,7 @@ class ScheduledUpdatesPromotion {
/**
* Name of the option to check.
*/
- const OPTION_NAME = 'woocommerce_analytics_immediate_import';
+ const OPTION_NAME = 'woocommerce_analytics_scheduled_import';
/**
* Constructor - attach action hooks.
@@ -111,6 +111,6 @@ class ScheduledUpdatesPromotion {
}
// Update the option to enable scheduled mode.
- update_option( self::OPTION_NAME, 'no' );
+ update_option( self::OPTION_NAME, 'yes' );
}
}
diff --git a/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php b/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
index f3370ccec4..e8fd27e2a7 100644
--- a/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
+++ b/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
@@ -54,18 +54,18 @@ class OrdersScheduler extends ImportScheduler {
const LAST_PROCESSED_ORDER_ID_OPTION = 'woocommerce_admin_scheduler_last_processed_order_id';
/**
- * Option name for storing whether to enable immediate order import.
+ * Option name for storing whether to enable scheduled order import.
*
* @var string
*/
- const IMMEDIATE_IMPORT_OPTION = 'woocommerce_analytics_immediate_import';
+ const SCHEDULED_IMPORT_OPTION = 'woocommerce_analytics_scheduled_import';
/**
- * Default value for the immediate import option.
+ * Default value for the scheduled import option.
*
* @var string
*/
- const IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE = 'yes';
+ const SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE = 'no';
/**
* Action name for the order batch import.
@@ -84,22 +84,22 @@ class OrdersScheduler extends ImportScheduler {
\Automattic\WooCommerce\Admin\Overrides\Order::add_filters();
\Automattic\WooCommerce\Admin\Overrides\OrderRefund::add_filters();
- if ( self::is_immediate_import_enabled() ) {
+ if ( self::is_scheduled_import_enabled() ) {
+ // Schedule recurring batch processor.
+ add_action( 'action_scheduler_ensure_recurring_actions', array( __CLASS__, 'schedule_recurring_batch_processor' ) );
+ } else {
// Schedule import immediately on order create/update/delete.
add_action( 'woocommerce_update_order', array( __CLASS__, 'possibly_schedule_import' ) );
add_filter( 'woocommerce_create_order', array( __CLASS__, 'possibly_schedule_import' ) );
add_action( 'woocommerce_refund_created', array( __CLASS__, 'possibly_schedule_import' ) );
add_action( 'woocommerce_schedule_import', array( __CLASS__, 'possibly_schedule_import' ) );
- } else {
- // Schedule recurring batch processor.
- add_action( 'action_scheduler_ensure_recurring_actions', array( __CLASS__, 'schedule_recurring_batch_processor' ) );
}
if ( Features::is_enabled( 'analytics-scheduled-import' ) ) {
- // Watch for changes to the immediate import option.
- add_action( 'add_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_added' ), 10, 2 );
- add_action( 'update_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_change' ), 10, 2 );
- add_action( 'delete_option', array( __CLASS__, 'handle_immediate_import_option_before_delete' ), 10, 1 );
+ // Watch for changes to the scheduled import option.
+ add_action( 'add_option_' . self::SCHEDULED_IMPORT_OPTION, array( __CLASS__, 'handle_scheduled_import_option_added' ), 10, 2 );
+ add_action( 'update_option_' . self::SCHEDULED_IMPORT_OPTION, array( __CLASS__, 'handle_scheduled_import_option_change' ), 10, 2 );
+ add_action( 'delete_option', array( __CLASS__, 'handle_scheduled_import_option_before_delete' ), 10, 1 );
}
OrdersStatsDataStore::init();
@@ -297,9 +297,8 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
/**
* Schedule this import if the post is an order or refund.
- * Note: This method is only called when immediate import is enabled
- * via the 'woocommerce_analytics_enable_immediate_import' filter.
- * Otherwise, orders are processed in batches periodically.
+ * Note: This method is only called when scheduled import is disabled
+ * (immediate mode). Otherwise, orders are processed in batches periodically.
*
* @param int $order_id Post ID.
*
@@ -307,7 +306,7 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
* @returns int The order id
*/
public static function possibly_schedule_import( $order_id ) {
- if ( ! self::is_immediate_import_enabled() ) {
+ if ( self::is_scheduled_import_enabled() ) {
return $order_id;
}
@@ -395,12 +394,12 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
}
/**
- * Handle changes to the immediate import option.
+ * Handle changes to the scheduled import option.
*
- * When switching from batch processing to immediate import,
+ * When switching from scheduled to immediate import,
* we need to run a final catchup batch to ensure no orders are missed.
*
- * When switching from immediate import to batch processing,
+ * When switching from immediate to scheduled import,
* we need to reschedule the recurring batch processor.
*
* @internal
@@ -408,9 +407,9 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
* @param mixed $new_value The new value of the option.
* @return void
*/
- public static function handle_immediate_import_option_change( $old_value, $new_value ) {
- // If switching from batch processing to immediate import.
- if ( 'no' === $old_value && 'yes' === $new_value ) {
+ public static function handle_scheduled_import_option_change( $old_value, $new_value ) {
+ // If switching from scheduled to immediate import.
+ if ( 'yes' === $old_value && 'no' === $new_value ) {
// Unschedule the recurring batch processor.
$action_hook = self::get_action( self::PROCESS_PENDING_ORDERS_BATCH_ACTION );
as_unschedule_all_actions( $action_hook, array(), static::$group );
@@ -418,8 +417,8 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
// Schedule an immediate catchup batch to process all orders up to now.
// This ensures no orders are missed during the transition.
self::schedule_action( self::PROCESS_PENDING_ORDERS_BATCH_ACTION, array( null, null ) );
- } elseif ( 'yes' === $old_value && 'no' === $new_value ) {
- // Switching from immediate import to batch processing.
+ } elseif ( 'no' === $old_value && 'yes' === $new_value ) {
+ // Switching from immediate to scheduled import.
// Set the last processed order date to now with 1 minute buffer to ensure no orders are missed.
update_option( self::LAST_PROCESSED_ORDER_DATE_OPTION, gmdate( 'Y-m-d H:i:s', time() - MINUTE_IN_SECONDS ) );
update_option( self::LAST_PROCESSED_ORDER_ID_OPTION, 0 );
@@ -430,7 +429,7 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
}
/**
- * Handle addition of the immediate import option.
+ * Handle addition of the scheduled import option.
*
* @internal
* @param string $option_name The name of the option that was added.
@@ -438,30 +437,30 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
*
* @return void
*/
- public static function handle_immediate_import_option_added( $option_name, $value ) {
- if ( self::IMMEDIATE_IMPORT_OPTION !== $option_name ) {
+ public static function handle_scheduled_import_option_added( $option_name, $value ) {
+ if ( self::SCHEDULED_IMPORT_OPTION !== $option_name ) {
return;
}
- self::handle_immediate_import_option_change( self::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE, $value );
+ self::handle_scheduled_import_option_change( self::SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE, $value );
}
/**
- * Handle deletion of the immediate import option.
+ * Handle deletion of the scheduled import option.
*
* @internal
* @param string $option_name The name of the option that was deleted.
*
* @return void
*/
- public static function handle_immediate_import_option_before_delete( $option_name ) {
- if ( self::IMMEDIATE_IMPORT_OPTION !== $option_name ) {
+ public static function handle_scheduled_import_option_before_delete( $option_name ) {
+ if ( self::SCHEDULED_IMPORT_OPTION !== $option_name ) {
return;
}
- self::handle_immediate_import_option_change(
- get_option( self::IMMEDIATE_IMPORT_OPTION, self::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE ),
- self::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE,
+ self::handle_scheduled_import_option_change(
+ get_option( self::SCHEDULED_IMPORT_OPTION, self::SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE ),
+ self::SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE,
);
}
@@ -703,20 +702,20 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
}
/**
- * Check whether immediate import is enabled.
+ * Check whether scheduled import is enabled.
*
* When the "analytics-scheduled-import" feature is disabled, only immediate
- * import is supported (returns true). When enabled, checks the option value.
+ * import is supported (returns false). When enabled, checks the option value.
*
* @internal
* @return bool
*/
- private static function is_immediate_import_enabled(): bool {
+ private static function is_scheduled_import_enabled(): bool {
if ( ! Features::is_enabled( 'analytics-scheduled-import' ) ) {
// If the feature is disabled, only immediate import is supported.
- return true;
+ return false;
}
- return 'no' !== get_option( self::IMMEDIATE_IMPORT_OPTION, self::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE );
+ return 'yes' === get_option( self::SCHEDULED_IMPORT_OPTION, self::SCHEDULED_IMPORT_OPTION_DEFAULT_VALUE );
}
}
diff --git a/plugins/woocommerce/src/Internal/Admin/Settings.php b/plugins/woocommerce/src/Internal/Admin/Settings.php
index 1e80057deb..51a7fc648f 100644
--- a/plugins/woocommerce/src/Internal/Admin/Settings.php
+++ b/plugins/woocommerce/src/Internal/Admin/Settings.php
@@ -351,15 +351,15 @@ class Settings {
if ( Features::is_enabled( 'analytics-scheduled-import' ) ) {
$settings[] = array(
- 'id' => 'woocommerce_analytics_immediate_import',
- 'option_key' => 'woocommerce_analytics_immediate_import',
+ 'id' => 'woocommerce_analytics_scheduled_import',
+ 'option_key' => 'woocommerce_analytics_scheduled_import',
'label' => __( 'Updates', 'woocommerce' ),
'description' => __( 'Controls how analytics data is imported from orders.', 'woocommerce' ),
'type' => 'radio',
'default' => null, // Default to null so we can know if it's a new site or an existing site. New sites will have the option set.
'options' => array(
- 'no' => __( 'Scheduled (recommended)', 'woocommerce' ),
- 'yes' => __( 'Immediately', 'woocommerce' ),
+ 'yes' => __( 'Scheduled (recommended)', 'woocommerce' ),
+ 'no' => __( 'Immediately', 'woocommerce' ),
),
);
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/AnalyticsImportsTest.php b/plugins/woocommerce/tests/php/src/Admin/API/AnalyticsImportsTest.php
index 2af63b1683..334b5f4127 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/AnalyticsImportsTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/AnalyticsImportsTest.php
@@ -76,7 +76,7 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
*/
public function tearDown(): void {
$this->clear_scheduled_actions();
- delete_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION );
+ delete_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION );
delete_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION );
parent::tearDown();
}
@@ -97,8 +97,8 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
public function test_status_returns_immediate_mode(): void {
wp_set_current_user( $this->admin_user );
- // Set to immediate mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'yes' );
+ // Set to immediate mode (scheduled disabled).
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'no' );
$request = new WP_REST_Request( 'GET', self::ENDPOINT . '/status' );
$response = $this->server->dispatch( $request );
@@ -123,8 +123,8 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
public function test_status_returns_scheduled_mode(): void {
wp_set_current_user( $this->admin_user );
- // Set to scheduled mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'no' );
+ // Set to scheduled mode (scheduled enabled).
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'yes' );
update_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION, '2025-11-26 05:30:00' );
$request = new WP_REST_Request( 'GET', self::ENDPOINT . '/status' );
@@ -149,7 +149,7 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->admin_user );
// Set to scheduled mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'no' );
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'yes' );
// Set last processed date in GMT.
$gmt_date = '2025-11-26 05:30:00';
@@ -203,7 +203,7 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->admin_user );
// Set to scheduled mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'no' );
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'yes' );
// Clear any scheduled actions that may have been created when setting the option.
$this->clear_scheduled_actions();
@@ -226,8 +226,8 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
public function test_trigger_fails_in_immediate_mode(): void {
wp_set_current_user( $this->admin_user );
- // Set to immediate mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'yes' );
+ // Set to immediate mode (scheduled disabled).
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'no' );
$request = new WP_REST_Request( 'POST', self::ENDPOINT . '/trigger' );
$response = $this->server->dispatch( $request );
@@ -262,7 +262,7 @@ class AnalyticsImportsTest extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->shop_manager_user );
// Set to scheduled mode.
- update_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION, 'no' );
+ update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'yes' );
// Clear any scheduled actions that may have been created when setting the option.
$this->clear_scheduled_actions();
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
index bc88f72e75..63edd5163c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
@@ -45,7 +45,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'disable_feature' ) );
// Delete option to simulate existing installation.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
$this->assertFalse( ScheduledUpdatesPromotion::is_applicable() );
@@ -60,7 +60,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'enable_feature' ) );
// Delete option to simulate existing installation (doesn't exist).
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
$this->assertTrue( ScheduledUpdatesPromotion::is_applicable() );
@@ -74,8 +74,8 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
// Enable feature flag.
add_filter( 'woocommerce_admin_features', array( $this, 'enable_feature' ) );
- // Set option to 'yes' to simulate new installation.
- update_option( 'woocommerce_analytics_immediate_import', 'yes' );
+ // Set option to 'yes' to simulate new installation (scheduled enabled).
+ update_option( 'woocommerce_analytics_scheduled_import', 'yes' );
$this->assertFalse( ScheduledUpdatesPromotion::is_applicable() );
@@ -90,7 +90,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'enable_feature' ) );
// Delete option to simulate existing installation (doesn't exist).
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
$note = ScheduledUpdatesPromotion::get_note();
@@ -113,7 +113,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
// Disable the feature (it's enabled by default in feature-config.php).
add_filter( 'woocommerce_admin_features', array( $this, 'disable_feature' ) );
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
$note = ScheduledUpdatesPromotion::get_note();
@@ -130,7 +130,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'enable_feature' ) );
// Delete option to simulate existing installation.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
ScheduledUpdatesPromotion::possibly_add_note();
@@ -151,7 +151,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'enable_feature' ) );
// Delete option to simulate existing installation.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
// Add note first time.
ScheduledUpdatesPromotion::possibly_add_note();
@@ -173,7 +173,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
*/
public function test_enable_action_updates_option() {
// Delete option to simulate existing installation.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
// Get the note.
$note = ScheduledUpdatesPromotion::get_note();
@@ -183,8 +183,8 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
$promotion = new ScheduledUpdatesPromotion();
$promotion->enable_scheduled_updates( $note );
- // Verify option was updated.
- $this->assertEquals( 'no', get_option( 'woocommerce_analytics_immediate_import' ) );
+ // Verify option was updated to 'yes' (scheduled enabled).
+ $this->assertEquals( 'yes', get_option( 'woocommerce_analytics_scheduled_import' ) );
}
/**
@@ -192,7 +192,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
*/
public function test_enable_action_ignores_wrong_note() {
// Delete option to simulate existing installation.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
// Create a different note.
$other_note = new Note();
@@ -203,7 +203,7 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
$promotion->enable_scheduled_updates( $other_note );
// Verify option was NOT updated (still null/doesn't exist).
- $this->assertFalse( get_option( 'woocommerce_analytics_immediate_import' ), 'Option should not exist' );
+ $this->assertFalse( get_option( 'woocommerce_analytics_scheduled_import' ), 'Option should not exist' );
}
/**
@@ -224,6 +224,6 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
}
// Reset options.
- delete_option( 'woocommerce_analytics_immediate_import' );
+ delete_option( 'woocommerce_analytics_scheduled_import' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
index 60b17a0b12..a92b32ca4a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
@@ -33,7 +33,7 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
// Clean up options.
delete_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION );
delete_option( OrdersScheduler::LAST_PROCESSED_ORDER_ID_OPTION );
- delete_option( OrdersScheduler::IMMEDIATE_IMPORT_OPTION );
+ delete_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION );
// Clean up any scheduled actions.
$this->clear_scheduled_batch_processor();
@@ -113,9 +113,9 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
}
/**
- * Test that handle_immediate_import_option_change unschedules batch processor when switching to immediate import.
+ * Test that handle_scheduled_import_option_change unschedules batch processor when switching to immediate import.
*/
- public function test_handle_immediate_import_option_change_unschedules_batch_when_enabling_immediate() {
+ public function test_handle_scheduled_import_option_change_unschedules_batch_when_disabling_scheduled() {
// Clear any existing scheduled actions.
$this->clear_scheduled_batch_processor();
@@ -126,8 +126,8 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
'Batch processor should be scheduled initially'
);
- // Switch from batch processing ('no') to immediate import ('yes').
- OrdersScheduler::handle_immediate_import_option_change( 'no', 'yes' );
+ // Switch from scheduled import ('yes') to immediate import ('no').
+ OrdersScheduler::handle_scheduled_import_option_change( 'yes', 'no' );
// Verify the batch processor is unscheduled.
$this->assertFalse(
@@ -137,26 +137,26 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
}
/**
- * Test that handle_immediate_import_option_change schedules batch processor when switching from immediate import.
+ * Test that handle_scheduled_import_option_change schedules batch processor when switching to scheduled import.
*/
- public function test_handle_immediate_import_option_change_schedules_batch_when_disabling_immediate() {
+ public function test_handle_scheduled_import_option_change_schedules_batch_when_enabling_scheduled() {
// Clear any existing scheduled actions.
$this->clear_scheduled_batch_processor();
- // Switch from immediate import ('yes') to batch processing ('no').
- OrdersScheduler::handle_immediate_import_option_change( 'yes', 'no' );
+ // Switch from immediate import ('no') to scheduled import ('yes').
+ OrdersScheduler::handle_scheduled_import_option_change( 'no', 'yes' );
// Verify the batch processor is scheduled.
$this->assertTrue(
$this->is_batch_processor_scheduled(),
- 'Batch processor should be scheduled when switching from immediate import to batch processing'
+ 'Batch processor should be scheduled when switching from immediate import to scheduled import'
);
// Verify the last processed date is set to approximately 1 minute ago.
$last_date = get_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION );
$this->assertNotFalse(
$last_date,
- 'Last processed date should be set when switching to batch processing'
+ 'Last processed date should be set when switching to scheduled import'
);
$expected_timestamp = time() - MINUTE_IN_SECONDS;
@@ -179,29 +179,29 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
}
/**
- * Test that handle_immediate_import_option_change does nothing for other transitions.
+ * Test that handle_scheduled_import_option_change does nothing for other transitions.
*/
- public function test_handle_immediate_import_option_change_ignores_other_transitions() {
+ public function test_handle_scheduled_import_option_change_ignores_other_transitions() {
// Clear any existing scheduled actions.
$this->clear_scheduled_batch_processor();
$action_hook = OrdersScheduler::get_action( 'process_pending_batch' );
- // Test transition from 'yes' to 'yes' (no change).
- OrdersScheduler::handle_immediate_import_option_change( 'yes', 'yes' );
+ // Test transition from 'no' to 'no' (no change - stays immediate import).
+ OrdersScheduler::handle_scheduled_import_option_change( 'no', 'no' );
$this->assertFalse(
$this->is_batch_processor_scheduled(),
'Batch processor should not be scheduled when option stays as immediate import'
);
- // Test transition from 'no' to 'no' (no change).
+ // Test transition from 'yes' to 'yes' (no change - stays scheduled import).
OrdersScheduler::schedule_recurring_batch_processor();
$scheduled_time = as_next_scheduled_action( $action_hook );
- OrdersScheduler::handle_immediate_import_option_change( 'no', 'no' );
+ OrdersScheduler::handle_scheduled_import_option_change( 'yes', 'yes' );
$this->assertEquals(
$scheduled_time,
as_next_scheduled_action( $action_hook ),
- 'Batch processor should remain scheduled when option stays as batch processing'
+ 'Batch processor should remain scheduled when option stays as scheduled import'
);
}