Find out how to have a custom CSS only applied to users with an active Easy Digital Downloads subscription.
If you have a membership created with Easy Digital Downloads (plus the Recurring Payments and Content Restriction addons) you may want to display some items differently to users who have an active subscription than to those who do not.
For example, if you are using a plugin that allows you to rate entries, you may want to restrict the display of the voting tool, and therefore the option to vote, only to users who have an active subscription.
And this is just an example, you can use any custom CSS you want.
Let’s see how:
Snippet for custom CSS to be applied only on users with an active EDD subscription
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 997 code snippets of this website, login or subscribe here.
In this code you use the wp_head
hook together with the has_active_subscription
conditional (which you get using the EDD_Recurring_Subscriber
class) to add a custom CSS to the header of the Easy Digital Downloads active subscriber pages.
That is, if the users do not have an active subscription, the custom
CSS will not be displayed to them. Instead, for active subscribers, it will apply the CSS you have embedded.
In this case, the CSS is designed to dispay the option to rate a plugin (Rate my post)
but you can modify it to your liking, you only have to modify that line of code. This would be the structure: '<style>.your-css-class { attribute: value; }</style>';
Conclusions
As you can see, it is possible to apply a custom CSS whose modifications are only visible to users who have an active Easy Digital Downloads subscription.
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. 🙂