I'm making a skin for The Grid plugin ().
All the products are virtual and downloadable — I've managed to make an add to cart function, but need to download products instantly too. Is there a meta key for the file url (combed the database and couldn't spot one) or a way to get it?
Currently I've got something that just returns an array:
$output .= '<p><a href="' . $tg_el->get_item_meta('_downloadable_files') . '" download target="_blank"><i class="fa fa-download"></i> Download Image</a></p>';
Thought I'd found a possible solution: but am not great with php and I'm unsure how to implement it.
Any pointers would be much appreciated!
I'm making a skin for The Grid plugin (https://theme-one/docs/the-grid/#developer_guide).
All the products are virtual and downloadable — I've managed to make an add to cart function, but need to download products instantly too. Is there a meta key for the file url (combed the database and couldn't spot one) or a way to get it?
Currently I've got something that just returns an array:
$output .= '<p><a href="' . $tg_el->get_item_meta('_downloadable_files') . '" download target="_blank"><i class="fa fa-download"></i> Download Image</a></p>';
Thought I'd found a possible solution: https://wordpress.stackexchange/a/199884/134263 but am not great with php and I'm unsure how to implement it.
Any pointers would be much appreciated!
Share Improve this question asked Jan 4, 2018 at 17:08 EllenEllen 111 silver badge3 bronze badges3 Answers
Reset to default 2<?php $downloads = $product->get_files();
foreach( $downloads as $key => $download ) {
echo '<p class="download-link"><a href="' . esc_url( $download['file'] ) . '">' . $download['name'] . '</a></p>';
} ?>
Check this.. Worked for me.
<?php
$downloads = $product->get_files();
foreach( $downloads as $key => $each_download ) {
echo '<p><a href="'.$each_download["file"].'" download><i class="fa fa-download"></i> Download Image</a></p>';
}
?>
as i used @dannie Herdyawans code snippet, it shows that get_files()
function is deprecated.
so instead of that use get_downloads()
function. listed below example.
$downloads = $productObj->get_downloads();
if ($downloads):
foreach ($downloads as $key => $each_download) {
$product->productDownloadUrl = $each_download['file'];
$product->productDownloadName = $each_download['name'];
}
endif;