Learn in this tutorial how to add the role assigned by Easy Digital Downloads when a subscription is reactivated 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”.
In a previous tutorial you learn how to remove this role when the subscription is cancelled, but in case the subscription is reactivated it is appropriate to assign it again.
This way you can use the “EDD Subscriber” role to give exclusive access or show something only to the users that have the active subscription.
Here’s how to do it:
Snippet to add the “EDD Subscriber” role when reactivating the subscription 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 hook
edd_recurring_reactivate_stripe_subscription to assign the user the role of “EDD Subscriber” when the subscription is reactivated.
This can be very 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 add the Easy Digital Downloads specific subscriber role when the subscription is reactivated.
Any questions? I read you 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. 😉