Learn in this tutorial how to display a button that allows the users to reactivate their Easy Digital Downloads subscription via code.
If you have a membership site created with Easy Digital Downloads (plus the Recurring Payments and Content Restriction addon) it is likely that more than once you have seen a subscription being cancelled due to some kind of problem with the payment method (card expiration, lack of funds…).
But if you are using the shortcode[edd_subscriptions]
you will have noticed that sometimes it shows the option to reactivate. The problem is that it does not always display it and the user does not know what to do to regain access to the content (sometimes creating new user accounts, subscriptions…).
You know that in OsomCode we always try to make it easy for the end user, so in this tutorial you will learn how to create a button that allows the user to reactivate the subscription with a single click. And you will be able to place it wherever you want.
Here’s how to do it:
Steps to display a button that allows the user to reactivate the subscription in Easy Digital Downloads
1. Create the shortcode
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case, you create a shortcode in which you use the EDD_Recurring_Subscriber
class to get the subscription data and the link that allows you to reactivate the subscription.
In addition, you make sure that the button is only shown to users with a cancelled or expired subscription and that can reactivate the subscription because they have a valid payment method.
The text shown is “Reactivate subscription” but you can change it to whatever you want.
The link is shown inside a button with a custom CSS class so you can style it as you wish (as we will see in step 3).
2. Insert the shortcode where you want
The advantage of shortcodes is that you can insert them anywhere on the web. In this case, the my account page or similar can be a good place.
Just type “[your_shortcode]” where you want it to be displayed, in this case [link_reactivate].
3. Give CSS styles to the button (optional)
Finally, you can customize how the button will be displayed by adding these lines to the end of the style.css file:
/* EDD subscription reactivate button styles */
button.reactivate-subscription a,
button.reactivate-subscription a:hover {
color: #fff;
text-decoration: none;
}
.reactivate-subscription {
margin: 20px 0;
}
This is just an example, the idea is that you adjust it according to the web design where you display it.
Conclusion
Do you want to make it easier for your web users to reactivate their subscriptions created with Easy Digital Downloads? Now you know how to display wherever you want a button that allows them to do it with a click.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂