Display an average rating with the Product Reviews plugin

The Product Reviews plugin allows your customers to give your products a review, including a star rating. This tutorial will allow you to place an average star rating at the top of your single download page, based on all the product’s reviews.

Product Reviews by Sunny Ratilal is an excellent plugin for Easy Digital Downloads that allows your customers to review your products.

While the product reviews are shown at the bottom of the product page, you might like to show an “average” star rating at the top of your product’s page.

Copy the following function below and paste it into your child theme’s functions.php

Place the following call to the function inside your single-download.php file, or the file you are using to show your download.

<?php echo sumobi_custom_show_average_star_rating(); ?>

Enable drag and drop download ordering in Easy Digital Downloads

This tutorial will show you how to achieve drag and drop ordering of downloads in Easy Digital Downloads. Downloads on your website (using the downloads shortcode) will be ordered exactly how you ordered them in the admin.

This tutorial will show you how to achieve drag and drop ordering of downloads in Easy Digital Downloads. Downloads on your website (using the [[downloads]] shortcode) will be ordered exactly how you ordered them in the admin.

To make this super easy for us, we’re first going to install the Simple Page Ordering plugin. Once installed, there’s 2 things we need to do to get it all running. Copy and paste each function below into your child theme’s functions.php or custom plugin.

First we need to tell the post type to support page-attributes. This adds a “Sort By Order” to the download admin screen, where you can use drag and drop ordering with the Simple Page Ordering WordPress plugin.

Second, we need to modify Easy Digital Downloads’ [[downloads]] shortcode query so that it sorts by menu_order. We also want to make sure order is set to ASC (Ascending).

That’s it!

How to add custom payment meta to the admin sales notification in Easy Digital Downloads

This quick tutorial will show you how you can add custom payment meta information to the admin sales notification email. It will also work for any data already in the payment meta array.

If you followed this tutorial, you will have created custom fields for your checkout form. The following code snippet assumes that you also used the same field names, edd_phone and edd_company. If you named your fields something different, simply update the names in the function below.

Paste the following function into your child theme’s functions.php or a custom plugin.

A creative use of EDD Hide Download and EDD Cross-sell & Upsell

EDD Hide Download (free) and EDD Cross-sell & Upsell (commercial) are both plugins I’ve recently built for Easy Digital Downloads.

EDD Hide Download allows you to hide a download from the custom post type archive page and anywhere where the standard downloads shortcode is being used (if you are using a custom query to retrieve the downloads, it’s easy to hide them from the custom loop also).

EDD Cross-sell & Upsell allows you hand-pick cross-sell products to display at checkout when a customer adds a specific product to their cart, or on single product pages as upsells.

Combine these two plugins together and you can do something rather neat.

Say you run a WordPress plugin shop, selling commercial plugins. Wouldn’t it be nice to be able to cross-sell your customers a type of service such as plugin installation, or even priority support without having these services appear directly in your product listings? Such services sometimes need to be directly related to a particular product and wouldn’t sit nicely amongst your other products.

With EDD Hide Download combined with EDD Cross-Sell & Upsell, you can still add these services as downloads within Easy Digital Downloads, yet only have them appear at checkout when the plugin is added to the cart.

Can you think of any other clever uses?

How to filter shortcodes in WordPress 3.6

There’s a hidden gem available in WordPress 3.6 that I’m excited about, and that is the shortcode_atts_{$shortcode} filter. It will allow developers to filter a shortcode by passing in new shortcode parameters, and even override existing ones. You can read more about it in this post by Mark Jaquith.

Taking advantage of shortcode_atts_{$shortcode} in a plugin

EDD Featured Downloads is a plugin I wrote for Easy Digital Downloads that allows you to display your featured downloads via a [[edd_featured_downloads]] shortcode.

It’s always bugged me that I had to copy the entire [[downloads]] shortcode from the core Easy Digital Downloads plugin, just to do a simple query to retrieve the correct posts.

Each time EDD was updated, I’d have to check my plugin and make sure that it matched EDD’s plugin for consistency. I even left myself a comment in the code, reminding myself why I created the shortcode in the first place:

* Featured Downloads Shortcode
* Created a new shortcode as filtering the shortcode atts is not possible yet
* https://core.trac.wordpress.org/ticket/15155
* @since 1.0

Shortcodes must include the new parameter to be filterable

One thing to note is that the shortcode you are filtering must have the new parameter included as the 3rd parameter in the shortcode_atts array. This will be the {$shortcode} in the filter name. WordPress 3.6’s core shortcodes (gallery etc) will have this new parameter added when it is released.

In the spirit of ditching my plugin’s shortcode, I submitted a minor patch to Easy Digital Downloads that will appear in v1.7.2 (At the time of writing, EDD is still on v1.7.1).

Here’s what that 3rd parameter looks like in the shortcode_atts array:

extract( shortcode_atts( array(
// an array of the shortcode's default options
), $atts, 'downloads' ) // the new 'downloads' parameter which will allow filtering

How to use the shortcode_atts_{$shortcode} filter

Now that the shortcode is filterable, we can build our filter. Going by the example above, the filter’s name would be:


Filtering the shortcode

The following code adds a new “featured” parameter to the [[downloads]] shortcode in Easy Digital Downloads.

function edd_fd_filter_downloads_shortcode( $out, $pairs, $atts ) {
    $out['featured'] = '';
    return $out;
add_filter( 'shortcode_atts_downloads', 'edd_fd_filter_downloads_shortcode', 10, 3 );

My EDD Featured Downloads plugin can now use EDD’s default downloads shortcode like this:

[[downloads featured="yes"]]

Now that we’ve added the new shortcode parameter, we need to do something with it. I want my plugin to filter the download query to show only posts with the edd_feature_download meta key, but only if featured is set to yes. Here we’re relying on a filter already available in the EDD downloads shortcode called edd_downloads_query.

function edd_fd_filter_downloads_query( $query, $atts ) {
    if( isset( $atts['featured'] ) && 'yes' == $atts['featured'] ) {
        $query['meta_key'] = 'edd_feature_download';

    return $query;
add_filter( 'edd_downloads_query', 'edd_fd_filter_downloads_query', 10, 2 );

The end result

The next version of my EDD Featured Downloads plugin will rely on both EDD 1.7.2+ and WP 3.6+ but I’ve managed to replace just over 160 lines of code with the two simple filters you see above.

This drastically reduces code, plugin maintenance as well as future-proofing it against future updates within the Easy Digital Downloads plugin.

How to add any Lightbox script to the Easy Image Gallery plugin

Easy Image Gallery is a plugin I created for creating and managing galleries outside of the WordPress editor. It comes packaged with support for fancyBox and prettyPhoto but it’s really easy to add another Lightbox should you need to do so.

Easy Image Gallery is a plugin I created for creating and managing galleries outside of the WordPress editor. It comes packaged with support for fancyBox and prettyPhoto but it’s really easy to add another Lightbox should you need to do so.

This tutorial will show you how to add Colorbox to the plugin, but the same methods apply for any Lightbox script. Place the following code snippets in your theme’s functions.php or any other file you have included into your theme.

1. Add Colorbox to Easy Image Gallery’s plugin settings

Easy Image Gallery has an included filter called easy_image_gallery_lightbox which allows you to add a new option to the Lightbox select menu. It also properly saves the new option to the database.

The first instance of colorbox is the value saved to the database which we check for in later examples, and the second is merely the label that shows up in the select menu.

Using the code above should get you this:


2. Load the required scripts for Colorbox.

Next we use wp_enqueue_script and wp_enqueue_style to load the JS and CSS files. We load the scripts onto an action hook included with Easy Image Gallery called easy_image_gallery_scripts. This action hook is fired inside a wp_enqueue_scripts action which will load the scripts onto the page.

By using Easy Image Gallery’s action hook, we ensure the scripts are only loaded if there’s a gallery, and that the images within the gallery are linked to larger images.

In the example above, I’ve placed the JS and CSS file in a folder called colorbox which is sitting in the theme’s main folder. Note the use of get_stylesheet_directory_uri() which will first look in the child theme, and then the parent if the files do not exist there.

Some Lightbox scripts like Colorbox also have images so we don’t want to forget those. In this instance we can just copy the images folder from the Colorbox download and include it in our colorbox folder. You’ll need to check with the Lightbox you are trying to implement as to where the images need to reside.

3. Initialise the Colorbox

Finally, we need to initialise the Colorbox script in our footer. Easy Image Gallery provides another handy action hook for doing this called easy_image_gallery_js. Again, by firing on this hook we ensuring that the JS will only load if there’s a gallery and the images link to larger versions.

If you want to add any additional options to the Lightbox, you would add them to JS below. Such options might be the Lightbox opening/closing effect, speed at which it opens etc.