I know that this question is already often asked but there is no exact answer for it.
I need to get the loggedin user id to change a value in the database for this user.
I tried 2 ways it didn’t work.
Way 1:
$user = get_current_user_id();
$sql = "UPDATE table_usermeta SET meta_value = '0' WHERE user_id= $user AND meta_key = 'alg_wc_ev_is_activated';";
Way 2:
$user = wp_get_current_user();
$user_id = $user->ID;
$sql = "UPDATE table_usermeta SET meta_value = '0' WHERE user_id= $user_id AND meta_key = 'alg_wc_ev_is_activated';";