Reputation: 583
I am using a third-party plugin to assign a role to a user when they purchase a subscription - there are two different roles depending on purchase (silver, gold)
However, if they cancel that subscription they keep the role.
How do I remove the role when they cancel as I don't want them to keep that role.
Upvotes: 1
Views: 1095
Reputation: 1
For everyone coming to this post, this feature is already built-in under WooCommerce/Settings/Subscriptions.
Upvotes: 0
Reputation: 11861
add_action('woocommerce_subscription_status_cancelled', 'wcs_maybe_remove_role', 10, 1);
function wcs_maybe_remove_role($subscription) {
$user_id = $subscription->get_user_id();
$user = new WP_User($user_id);
$user->remove_role('silver');
$user->remove_role('gold');
}
Upvotes: 3