Learn in this tutorial how to remove the role assigned by Easy Digital Downloads when the subscription is cancelled by code.
One of the most common options when creating a membership is to use the Restrict Content Pro plugin. In fact, this is what I use on this page.
But in some occasions, for example if you also want to sell digital products, Easy Digital Downloads can be a very interesting option.
To adapt EDD to create a membership you need 2 extra addons:
- Recurrent Payments
- Content Restriction
If you are using this combination you will have noticed that EDD grants a specific role to the subscriber which is called “EDD Subscriber”.
What happens is that the subscriber keep that role even if they cancel the subscription but, if you use that role to give exclusive access you may want to remove it when the subscription is cancelled.
Here is how to do it:
Snippet to remove the “EDD Subscriber” role when the subscription is cancelled in Easy Digital Downloads
Add the following code at the end of functions.php or in your functionality plugin:
In this case, you use the
edd_subscription_cancelled hook to switch the user from the “EDD Subscriber” role to subscriber.
This can be handy if you want to grant some specific functionalities to the “EDD Subscriber” role and make sure that only those who have the active subscription have access to them.
As you can see, with a few lines of code you can remove the specific Easy Digital Downloads subscriber role when the subscriber’s subscription is cancelled.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉