Lee Willis

Sorting the list of downloadable files in WP e-Commerce


Those of you who run stores with downloadable products may well have struggled with the following problem. If you try an attach an existing file to a product (Either because the same file is supplied with different products, or you have product variants that you need to set downloads against), then you may well have run into the following:

This list is a bit of a nightmare to find the file you want. It’s not sorted by anything obvious – not name, and not date-modified as far as I can tell. Finding a file is a bit of a scroll-and-hope affair. Much better to have a nice, ordered list like this:

This is an itch I’ve been wanting to scratch for a while now, and it turns out the code is pretty simple. Just drop the following in your theme’s functions.php file and revel in the glory of a nice, ordered file list.

function site_plugin_custom_sort_function ( $a, $b ) {
  return strtolower($a['display_filename']) > strtolower($b['display_filename']);

function site_plugin_sort_download_list ( $download_list ) {
  // Sort the multidimensional array
  usort($download_list, "site_plugin_custom_sort_function");
  return $download_list;
add_filter ( 'wpsc_downloadable_file_list', 'site_plugin_sort_download_list' );


  1. Hi Lee …

    You must have read my mind as I was just thinking about the same thing! I’m still running 3.7 on the count of a bunch of hacks/customizations. Tried dropping the code in there and it didn’t work … would it be easy to tweak it for us dinosaurs?



  2. Seem to have it working for 3.7.8. I’ve added Lee’s functions to my Theme’s functions.php and in ‘wp-e-commerce > wpsc-includes > form-display-functions.php’ just below the line:

    $product_files = get_product_meta($product_id, ‘product_files’);

    I’ve added:

    $file_list = site_plugin_sort_download_list ($file_list) ;

    These are around line 136 on my ‘form-display-functions.php’ but I have a bunch of customizations in there so that line number might not match up with your copy.

    Working so far … will let you know if it blows up.

    Thanks again, Lee!


Leave a Reply

Required fields are marked *.