Code below is used on a Magento 2 website to display a download link for product instructions etc. We have some products that require more than one PDF, we can enter these is the Download attribute (dz_downloads) separated by a comma, but only one displays?
If anyone could help amend the code so that we can display more than one PDF download per product it would be appriciated.
<?php
$product = $block->getProduct();
$blockObj = $block->getLayout()->createBlock('Dzinehub\Core\Block\Main');
$mediaUrl = $blockObj->getMediaUrl().'pdf_upload/';
$BaseUrl = $blockObj->getBaseUrl();
$mediapath = $blockObj->getMediaDir();
$pdfOption = 'dz_downloads';
$pdfoptionvalue = $product->getData($pdfOption);
$pdf_files = explode(',', $pdfoptionvalue);
foreach ($pdf_files as $pdf_file) {
$pdfURL = $mediaUrl."".$pdf_file;
$pdfPath = $mediapath .'/pdf_upload/' .$pdf_file;
} ?>
<?php if($pdf_file != "" && file_exists($pdfPath)){ ?>
<div class="dz_pdf">
<a href="<?php echo $pdfURL; ?>" download><?php echo $pdf_file; ?></a>
</div>
<?php } ?>