admin管理员组

文章数量:1336289

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.

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.

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.

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.

Share Improve this question asked Jan 2, 2016 at 13:06 Stanley UmeanozieStanley Umeanozie 1951 gold badge2 silver badges6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

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

<?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 work good.

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

UPDATE

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

本文标签: Display File Types For Woocommerce Downloadable Products On Product Page