• Resolved Marcus Karlos

    (@power2009)


    Help with that..

    <?php

    global $product;

    $downloads = $product->get_files();

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

    echo ‘<p> Formats: ‘. $formats .'</p>’;

    ?>

    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:
    https://wordpress.stackexchange.com/questions/477/how-do-i-get-the-size-of-an-attachment-file/546#546

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Marcus Karlos

    (@power2009)

    <?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)?

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @power2009 It seems you got the code needed to output the file size, but you still need to get the ID of the file itself, correct? This really depends on where and how you are getting the list of files in the first place. I am not sure if we would be able to provide the code to help you, but if you can confirm what you have we can take a look and direct as needed.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved. If you have any further questions, a new thread can be opened.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do that. File Size Output for DG Products’ is closed to new replies.