The other day I got an interesting support thread for Easy Digital Downloads, asking for the list of files, and their sizes be displayed when viewing a product. Being that I only use it to sell WordPress plugins, it seemed pretty minor, but if you were dealing with larger Audio/Video files, or your consumers used their mobile devices frequently, I could see how this would be useful. So I put together a quick, single file, plugin that is now available in the EDD Library Repo on Github.

First, here’s the primary function that is run:

function edd_ck_show_file_sizes( $post_id ) {
	$files = edd_get_download_files( $post_id, null );
	$decimals = 2;
	$sz = 'BKMGTP';
	$header = _n( 'File Size', 'File Sizes', count( $files ), 'edd' );
	echo '<h5>' . $header . '</h5>';
	echo '<ul>';
	foreach( $files as $file ) {
		$bytes = filesize( get_attached_file( $file['attachment_id'] ) );
		$factor = floor((strlen($bytes) - 1) / 3);
		echo '<li>' . $file['name'] . ' - ' . sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor) ) . @$sz[$factor] . '</li>';
	echo '</ul>';
add_action( 'edd_after_download_content', 'edd_ck_show_file_sizes', 10, 1 );

Now, a quick overview. Basically what we’re doing is looking for all the uploaded media items attached as ‘Downloads’ to this product. Once we get them, we’re iterating through them. You see this in the line

$files = edd_get_download_files( $post_id, null );

After that we do some setup, only wanting 2 decimal places, setting up the title of the list (following the numeric localization method), and you’ll notice that odd variable BKMGTP. What is this? Well it’s used to make the output of the size calculation human readable. It’s for “Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes, and Petabytes”. I’ve never seen a use case of someone selling Tera/Petabyte files on EDD, but who am I to judge.

After that, a little loop to run each calculation by powers of 1024, and we’re good to go!

You can go grab the full plugin-ready file here.

Image credit(CC): John Trainor

Posted by Chris Klosowski

Chris Klosowski is the Director of Technology at Sandhills Development, LLC, creators of fine WordPress plugins, and ecommerce solutions.


  1. […] EDD? Here’s a very handy snippet to show file sizes for downloads on the product pages. Sumobi also released a free extension for add-to-cart redirects on […]


    1. This is a great suggestion, thanks!


  2. Hi Chris, thanks for the code! I’ve added this to functions.php and then on my product page I’ve added;

    $post = get_post();
    edd_ck_show_file_sizes( $post->ID );

    which is almost working. Strangely, if I upload a file with the fes submission form it shows the size as 0.00, but if I upload a file from the WordPress dashboard it seems to show the size correctly. Any idea why this might be? Screenshot;

    Thanks again.



    1. Hi, I am facing the same problem. As I found out, this is all from the fact that the plugin FES does not add parameter ‘attachment_id’ to the table ‘wp_postmeta’ in line ‘edd_download_files’.
      I found the file plugins/edd-fes/classes/fields/multiple_pricing.php
      and in the lines 513 and 523 added: ‘attachment_id’ => fes_get_attachment_id_from_url( $url, $user_id )
      And it all worked)
      But I don’t know if all this is right and there will be no problems in the future …) Thanks


  3. hi, how to show
    file name with extension ?
    name : test size : 39 kb type: zip



  4. There’s definately a great deal to know about this issue.
    I love all of the points you have made.


  5. I’m really impressed together with your writing abilities and also with the structure in your weblog.
    Is that this a paid topic or did you customize it yourself?
    Anyway keep up the nice high quality writing, it’s rare to look a nice weblog like this one nowadays.

    my site;


  6. Today, I went to the beach front with my kids. I found a sea
    shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
    placed the shell to her ear and screamed. There
    was a hermit crab inside and it pinched her ear. She never
    wants to go back! LoL I know this is entirely off topic but I had to tell


  7. Cytotec (Misoprostol) is used for reducing the risk of stomach ulcers in certain patients who take nonsteroidal anti-inflammatory drugs (NSAIDs).
    Buy Cytotec (Misoprostol) right now – and save your money.
    Only 1.85$ Per pill!


  8. That is really fascinating, You’re an overly skilled blogger.
    I have joined your rss feed and stay up for in the hunt for more of your fantastic post.
    Also, I have shared your web site in my social networks!

    My webpage …


  9. Thanks for sharing your thoughts about code. Regards


  10. Amoxicillin is a penicillin antibiotic. It kills or stops the growth of some bacteria. This medicine is used to treat many kinds of infections. It will not work for colds, flu, or other viral infections.
    Buy Amoxicillin right now – and save your money.
    Only 0.44 usd per pill!


Leave a reply

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