If you are setting an expiry time on membership roles, you might want to add a new role when the membership role expires.
You can do this with the following snippet. Note that if you are assigning a new role to replace an expired role, you will need to have created that new role in WooCommerce > Settings > Members Only > Roles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add new user role when existing role expires | |
* Note that the new role will need to be created first | |
*/ | |
function prefix_after_expired_user_remove_role( $user, $role ) { | |
// This will add the 'Expired' user role. | |
// Ensure that you have already created this user role in WooCommerce > Settings > Members Only > User Roles | |
$user->add_role( 'expired' ); | |
} | |
add_action( 'wcmo_after_expired_user_remove_role', 'prefix_after_expired_user_remove_role', 10, 2 ); |
Here’s how to add a snippet.