I wrote the folowing timer in my function.php file. It should be called every certain time (3 minutes) but it doesn't work at all.
function myprefix_custom_cron_schedule( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 minutes' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );
if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) {
wp_schedule_event( time(), 'every_three_minutes', 'myprefix_cron_hook' );
}
add_action( 'myprefix_cron_hook', 'do_anything' );
and here is my function:
function do_anything($user_id) {
update_user_meta( $user_id, 'alg_wc_ev_is_activated', '0' );
wp_redirect( wc_get_page_permalink( 'myaccount' ) );
exit();
}
I don't know, why it doesn't work. Am I missing something in code?
$user_id
is, and it can't redirect, because it isn't connected to a user session.