Learn how to restrict viewing and adding comments only for people who have purchased through Easy Digital Downloads (EDD) using code.
Did you notice that OsomCode has restricted comments to subscribers only?
In this tutorial I explained how to do it using Restrict Content Pro.
But what happens if you’re interested in replicating this system with Easy Digital Downloads?
This would allow you to provide extra value by giving access to comments only to customers.
Interesting, isn’t it? Do you also want to limit the comments only to those who have purchased a product/download from EDD?
Here’s the code you need:
Instructions to hide comments to anyone who hasn’t purchased an EDD product
1. Create a snippet that limits comments
Add the following code snippet to your functionality plugin:
To see this and another 965 code snippets of this website, login or subscribe here.
In this case you use the edd_has_user_purchased
function to detect if the current user has already purchased that product and combine it with a conditional tag.
So if the reader doesn’t meet the condition, this block takes care of removing the comments using Genesis Framework hooks.
On the other hand, you limit the snippet to the courses we’ve used as an example, without affecting the rest of your CPTs or posts where the comments will still be open. Of course, you can change this and adjust it to your needs.
In addition, with the above snippet you take the opportunity to place a message or CTA in the hidden area so that those who don’t have access understand why they don’t see the comments and you can invite them to buy or identify themselves.
Again, you can (and should) modify this text to your liking.
2. Customize the CSS of the CTA in the comment area
Once you’ve hidden the comments from non-customers, you just need to style the message that appears in the restricted area.
To do this, add this block to the end of style.css:
To see this and another 965 code snippets of this website, login or subscribe here.
By inserting these CSS lines you ensure that the message is displayed as in this website (osomcode.com).
If you want the padlock to be displayed, add this file to the /assets/images/ path (hold down the alt key when clicking on the link to download it).
Your theme may not have the same folder structure and instead of /assets/images/ it may just be /images/ or similar. If so, put it in that folder and adjust the path accordingly.
You can also upload the image to your media library and place the full path in the ULR. It would look something like this:
background-image: url('https://osomcode.com/wp-content/uploads/2022/01/lock.svg');
As always, I invite you to customize the size of the box, border, corporate colors…
Conclusions
Now you know how to hide the comments to users who have not purchased an EDD product and add a custom message inviting them to buy the product.
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. 😉