Easy Digital Downloads – Enabling Comments & Adding “Purchased” and “Author” Badges

Easy Digital Downloads is the perfect WordPress plugin for those who are selling digital and other non-physical products using WordPress. It is not bloated with features, instead it only comes with the features most users will definitely need, as stated in the plugin description:

Rather than attempting to provide every feature under the sun, Easy Digital Downloads makes selling digital simple and complete by providing just the features you need.

So in this tutorial we’ll cover one of those features that are not vital to the plugin but useful for some users to have. To be more specific we’ll focus on the comments.

This will be a series of tutorials and in this first part of the series we’ll enable comments and add “purchased” and “author” badges.

Enabling Comments

By default comments functionality is not activated for EDD downloads. EDD comes with a filter named edd_download_supports which allows us to change which WordPress features are supported by the custom post type added by EDD.

Once you add that code and visit the “edit download” page in the WP admin you will see the “Discussion” options where you can enable comments:

When enabled, the comments will show up on the single download/product page.

Adding Badges

On marketplaces such as Themeforest or CreativeMarket the comments made by a customer of the product show a badge with the text “purchased” as in the screenshot below.

To add such a badge we will hook into the WordPress get_comment_author_link filter which allows us to add HTML right after the comment author name.

Below is the simplest example of adding additional HTML right after the comment author name:

That would of course add the badge to all places where comment author is being displayed, so we need to do a few checks to make sure:

  • We are on a download/product page
  • We are inside of a WordPress loop
  • We are in the main query

Doing those checks ensures we are only appending our HTML in the comments listing on a download page.

Now that we know we are only altering what we need to, we can proceed with adding the actual badges.

Purchased Badge

We will use the EDD function edd_has_user_purchased() to check if the user who left the comment has purchased the download.

That function needs 2 parameters: user ID and download ID. The user ID we can get using get_comment() and download ID using get_the_ID().

Author Badge

Another useful badge to display would be on the comments made by the owner/author of the download. For that we will need to check if the ID of the user who left the comment is the same as the user who owns the download.

We already have the user ID ( $commenter_id ) and we just need to get the author id using get_the_author_meta().

And that is our final code which displays “purchased” and “author” badges. You’ll of course need some CSS to style the badges and CSS is not what this tutorial is about but here’s what you could use:

Final Words

That’s all for part 1 of this tutorial series.

In part 2 we will be going over restricting the access to viewing and making comments based on whether the current user has purchased the download. If you’re interested in that make sure to subscribe to our newsletter ( form in the sidebar ) and we’ll let you know once it’s published.

If you liked this article/tutorial please consider sharing it on Twitter or Facebook, it would be of great help.

Tags: , ,
Previous Post

Easy Digital Downloads – Restricting Comments Viewing & Submission


    • Tina
    • November 28, 2018

    This is just what I was looking for, to turn on comments…but being that I am no coder, I am unfamiliar with WHERE to put this code. Can you please tell me what file and where I should be putting this in the file? Thank you for helping a total novice! 🙂

      • BobaWebDev
      • November 29, 2018

      Hi Tina. All the PHP code can go in functions.php of the theme (but I suggest you do it with a child theme). The CSS code goes in style.css or in WP admin > Appearance > Customize > Additional CSS.

    • dariush
    • February 16, 2019

    Thanks for codes. But the first (for purchased badge) doesn’t work for me and the last one breaks down the site. What is the problem you think?

      • BobaWebDev
      • March 1, 2019

      What’s the error you’re getting ( on the screen or in the logs )?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.