How can I Run a sql (update) after 12 hours after the user login (for Woocommerce users)
After 12 hours after a user login, I want to run a sql/ function to update a value in the database.
To set a value to '0' again.
You could do something like this (this code has not been testedt).
function schedule_sql_command($user_login, $user) {
// 12 hours in seconds.
$from_now = 12 * 60 * 60;
// schedule a call to a custom hook passing in the user's ID
wp_schedule_single_event(time() + $from_now, 'run_sql_command', array( $user->ID) );
}
// this is the custom hook that takes the user_id as a param
function run_sql_command($user_id) {
global $wpdb;
$wpdb->query("Your query here using $user_id");
}
// Hook when user logs in
add_action( 'wp_login', 'schedule_sql_command') ;
do_action()
is the problem. Should write add_action()
. but it doesn't change the vlaue in the databse anway :(
Commented
Feb 26, 2021 at 8:07
add_action()
code updated. Try using the crontrol plugin to see scheduled events
Commented
Feb 26, 2021 at 8:35