admin管理员组

文章数量:1317898

I'm trying to add the direct download link of a product to a button, but I'm stuck.

What I tried is this

<a href="<?php echo $product->downloadable_files; ?>">Download</a>

And of course it didn't work.

What is the proper code to get the product's download url?

I'm trying to add the direct download link of a product to a button, but I'm stuck.

What I tried is this

<a href="<?php echo $product->downloadable_files; ?>">Download</a>

And of course it didn't work.

What is the proper code to get the product's download url?

Share Improve this question asked Aug 27, 2015 at 9:30 Punct UlicaPunct Ulica 2171 gold badge3 silver badges8 bronze badges 1
  • Note that you should never output the actual downloadable file to a user, but instead grant the user permissions on a downloadable, and output that permissions link. Like this, a user can share a link to a downloadable that does not require authentication. – kontur Commented Dec 10, 2018 at 12:20
Add a comment  | 

1 Answer 1

Reset to default 9

Here is the code to get the download link for a downloadable product in WooCommerce.

$downloads = $product->get_downloads();

foreach( $downloads as $key => $each_download ) {
  echo '<a href="'.$each_download["file"].'">Download</a>';
}

本文标签: post metaWhat is the code to get the download link for a product in WooCommerce