I have added the code below to my WooCommerce site to display the file format of a downloadable asset.
to be displayed on a single product page
For ZIP files, I would like the display to indicate the files which are contained within the compressed archive, so the shoppers of simple/downloadable products know the formats of the product data which they will receive. How can this be achieved please?
global $product;
$downloads = $product->get_files();
foreach( $downloads as $key => $each_download ) {
$info = pathinfo($each_download["file"]);
$ext = $info['extension'];
$formats .= $ext . ", ";
}
echo '<p> File Format: '. $formats .'</p>';
?>```
2
Answers
You can use the ZipArchive to gather the index of the files within the zip.
Ensure that you have the module installed as detailed here https://www.php.net/manual/en/zip.installation.php
You can tailor it to your needs.
Hello like @user6316291 said, zipArchive works.
Since it’s in WooCommerce, you can try this code.
you can find the gist here: https://gist.github.com/Preciousomonze/88e30062982a20b2f9af98e834964969