I have a membership wordpress site. I want to suspend user after sixth month from the registration date. So that user purchase our plan/subscription. I want everything without any plugin.
How can i do this?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have a membership wordpress site. I want to suspend user after sixth month from the registration date. So that user purchase our plan/subscription. I want everything without any plugin.
How can i do this?
You would need to do a Cron. Get all user who where registered before 6 months ago and change their role to something else. in this example i have user 'expired' but you would need the create this role before you could use it.
add_action('wp', function() {
if ( !wp_next_scheduled( 'check_for_expired_users' ) ) {
wp_schedule_event( time(), 'daily', 'check_for_expired_users');
}
});
function check_for_expired_users() {
$users = get_users([
'role__not_in' => array('expired'),
'date_query' => array(
array(
'before' => '6 months ago',
)
)
]);
foreach ($users as $u) {
$u->set_role( 'expired' );
}
}