WooCommerce::register_recurring_actions
Register recurring actions.
Method of the class: WooCommerce{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WooCommerce = new WooCommerce(); $WooCommerce->register_recurring_actions();
WooCommerce::register_recurring_actions() WooCommerce::register recurring actions code WC 10.7.0
public function register_recurring_actions() {
// Remove any unwrapped actions that may have been scheduled before scheduling the new wrapped ones.
$this->unschedule_unwrapped_actions();
// Check if Action Scheduler is available.
if ( ! function_exists( 'as_schedule_recurring_action' ) || ! function_exists( 'as_schedule_single_action' ) ) {
return;
}
$gmt_offset = get_option( 'gmt_offset' );
$offset_hours = ( $gmt_offset > 0 ? '-' : '+' ) . absint( $gmt_offset ) . ' hours';
// Schedule daily sales event at midnight tomorrow.
$scheduled_sales_time = strtotime( '00:00 tomorrow ' . $offset_hours );
if ( false === $scheduled_sales_time ) {
$scheduled_sales_time = strtotime( '00:00 tomorrow' );
}
as_schedule_recurring_action( $scheduled_sales_time, DAY_IN_SECONDS, 'woocommerce_scheduled_sales', array(), 'woocommerce', true );
$held_duration = get_option( 'woocommerce_hold_stock_minutes', '60' );
if ( '' !== $held_duration ) {
/**
* Determines the interval at which to cancel unpaid orders in minutes.
*
* @since 5.1.0
*/
$cancel_unpaid_interval = apply_filters( 'woocommerce_cancel_unpaid_orders_interval_minutes', absint( $held_duration ) );
as_schedule_single_action( time() + ( absint( $cancel_unpaid_interval ) * 60 ), 'woocommerce_cancel_unpaid_orders', array(), 'woocommerce', true );
}
$tomorrow_3am = strtotime( 'tomorrow 03:00 am ' . $offset_hours );
if ( false === $tomorrow_3am ) {
$tomorrow_3am = strtotime( 'tomorrow 03:00 am' );
}
$tomorrow_6am = strtotime( 'tomorrow 06:00 am ' . $offset_hours );
if ( false === $tomorrow_6am ) {
$tomorrow_6am = strtotime( 'tomorrow 06:00 am' );
}
// Delay the first run of `woocommerce_cleanup_personal_data` by 10 seconds
// so it doesn't occur in the same request. WooCommerce Admin also schedules
// a daily cron that gets lost due to a race condition. WC_Privacy's background
// processing instance updates the cron schedule from within a cron job.
as_schedule_recurring_action( time() + 10, DAY_IN_SECONDS, 'woocommerce_cleanup_personal_data', array(), 'woocommerce', true );
as_schedule_recurring_action( $tomorrow_3am, DAY_IN_SECONDS, 'woocommerce_cleanup_logs', array(), 'woocommerce', true );
$next_run_timestamp = as_next_scheduled_action( 'woocommerce_cleanup_sessions', array(), 'woocommerce' );
if ( $next_run_timestamp !== $tomorrow_6am ) {
as_unschedule_all_actions( 'woocommerce_cleanup_sessions' );
as_schedule_recurring_action( $tomorrow_6am, 12 * HOUR_IN_SECONDS, 'woocommerce_cleanup_sessions', array(), 'woocommerce', true );
}
as_schedule_recurring_action( $tomorrow_6am, 15 * DAY_IN_SECONDS, 'woocommerce_geoip_updater', array(), 'woocommerce', true );
// Schedule the action to send tracking events if tracking is enabled.
$this->schedule_tracking_action();
as_schedule_recurring_action( $tomorrow_3am, DAY_IN_SECONDS, 'woocommerce_cleanup_rate_limits_wrapper', array(), 'woocommerce', true );
as_schedule_recurring_action( time(), DAY_IN_SECONDS, 'wc_admin_daily_wrapper', array(), 'woocommerce', true );
// Note: this is potentially redundant when the core package exists.
as_schedule_single_action( time() + 10, 'generate_category_lookup_table_wrapper', array(), 'woocommerce', true );
}