Automattic\WooCommerce\Internal\Admin\Schedulers
OrdersScheduler::handle_scheduled_import_option_change
Handle changes to the scheduled import option.
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 to scheduled import, we need to reschedule the recurring batch processor.
Метод класса: OrdersScheduler{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = OrdersScheduler::handle_scheduled_import_option_change( $old_value, $new_value );
- $old_value(разное) (обязательный)
- The old value of the option.
- $new_value(разное) (обязательный)
- The new value of the option.
Код OrdersScheduler::handle_scheduled_import_option_change() OrdersScheduler::handle scheduled import option change WC 10.5.2
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 );
// 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 ( '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 );
// Schedule the recurring batch processor.
self::schedule_recurring_batch_processor();
}
}