Learn how to restrict viewing and adding comments only for people who have purchased through Easy Digital Downloads (EDD), via 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 plugin is very popular for managing digital sales and allows you to achieve something very similar to RCP when combined with the “Content Restriction”addon.
Therefore, it also allows you to give an extra value by giving access to comments only to customers.
Interesting, isn’t it? Do you also want to restrict comments only to those who have purchased a product/download from EDD?
Here’s the code you need:
Instructions to hide comments to those who have not purchased an EDD product
To implement this tutorial you will need to use EDD in combination with its “Content Restriction” addon.
This extension allows you to link an EDD product to a content. For example, you can tell it that when X product/download is purchased, to give access to X course.
1. Add the content restriction
Choose the content you want to restrict, for example, a course.
Within the course, go to the bottom where the “Content restriction” metabox is located and indicate the purchase of which product will give access to this course from the dropdown.

2. Create a snippet that limits comments
Add the following code snippet to your functionality plugin:
To see this and another 919 code snippets of this website, login or subscribe here.
When using Easy Digital Downloads in combination with the Content Restriction addon to manage access to content, you need to add a conditional tag along with a function that checks if the user has access. In this case it is edd_cr_user_has_access.
So, if the reader does not meet the condition, this block takes care of deleting the comments using Genesis Framework hooks.
On the other hand, you limit the snippet to the courses we have 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 do not have access understand why they do not 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 have 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 at the end of style.css:
To see this and another 919 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 path /assets/images/ (hold down the alt key when clicking on the link to download it).
It is possible that your theme does not have the same folder structure and instead of /assets/images/ it is just /images/ or similar. If so, place 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 register or identify themselves.
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. 😉