I offer downloadable products with woocommerce and each product is allowed to have multiple files.

I would like to display the file types/formats on the product page so users know what each product contains. Please see the image below.

enter image description here

One idea I have thought of is to get the names of the attached files, and then somehow print only the last four characters of each one. But I cannot figure out how to write a function that would make it work.


Place the following code in your meta.php template file immediately after the lines where it prints the categories and tags. Please note, the standard practice is that you shall copy the meta.php template file to your theme folder. So to override meta.php, copy: woocommerce/templates/single-product/meta.php from plugin folder to yourtheme/woocommerce/templates/single-product/meta.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>';

  • Thank You. This is much better than what i had thought it would look like. I have accepted this answer since it is exactly what i asked for, but I would like assistance with something I didn't think would be a problem. How do I wrap a <code><span class="test"></span></code> around each format? – Stanley Umeanozie Jan 2 '16 at 17:46
  • 1
    To achieve that, change the $formats code line to $formats .= '<code><span class="test">' . $ext . '</span></code>, '; – Prasad Nevase Jan 3 '16 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.