php – How do that. File Size Output for Downloadable Products


Help with that..

get_files();

foreach( $downloads as $key => $each_download ) {
$info = pathinfo($each_download(“file”));
$ext = $info(‘extension’);
$formats .= $ext . “, “;
}

echo ‘

Formats: ‘. $formats .’

’;

?>

How do that too for the File Size? I have a Woo for Digital Products.. But anyone codes not worked for OutPut File Size.. But File format output work good.

I try this:
How do I get the size of an attachment file?

Not work

The code in this thread works great! But only for the file extension, I asked if there is the same code for outputting the size of the file added to the Woo product (as a virtual, downloadable)? I try use all codes from forums where is WP filesize (file size output) but not worked nothing


<?php

$attach_id = 8677;
$meta = wp_get_attachment_metadata( $attach_id );

if ( isset( $meta(‘filesize’) ) )
$file_size = $meta(‘filesize’);
elseif ( $file = get_attached_file( $attach_id ) )
if( file_exists( $file ) )
$file_size = filesize( $file );

echo size_format( $file_size );
?>

that work but needed past ID = 8677 (Manual ..) how do that, get a attached file id (Auto to per Product)?