Php Woocommerce产品下载URL

Php Woocommerce产品下载URL,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在为网格插件()制作一个皮肤 所有的产品都是虚拟的,可以下载——我已经设法添加到购物车功能,但也需要立即下载产品。是否有一个文件url的元键(在数据库中搜索,但找不到一个)或获取它的方法 目前,我得到了一个只返回数组的东西: $output .= '<p><a href="' . $tg_el->get_item_meta('_downloadable_files') . '" download target="_blank"><i class="fa f

我正在为网格插件()制作一个皮肤

所有的产品都是虚拟的,可以下载——我已经设法添加到购物车功能,但也需要立即下载产品。是否有一个文件url的元键(在数据库中搜索,但找不到一个)或获取它的方法

目前,我得到了一个只返回数组的东西:

$output .= '<p><a href="' . $tg_el->get_item_meta('_downloadable_files') . '" download target="_blank"><i class="fa fa-download"></i> Download Image</a></p>';
$output.='

';
我想我已经找到了一个可能的解决方案:但是我对php不是很在行,我不知道如何实现它


任何指点都将不胜感激

Woocommerce可下载的是数组,正如您在后端看到的,它为您提供了添加多个可下载数组的选项

假设您在可以启动全局变量
$product
的产品模板上,您可以使用方法
$product->get_files()从其他帖子提到的产品中获取可下载列表
这将为您提供一个可下载文件的数组,您必须循环每个数组项以获取名称和链接等数据,您必须使用
foreach
循环

我不知道你到底想在哪里添加这个,但根据你的代码,你可以这样做

// Declaring $product variable from woocommerce, this isn't needed if previously declared
global $product;

// get all downloadable files from the product
$files = $product->get_files(); 

//Loop through each downloadable file
foreach( $files as $file ) {
    //store the html with link and name in $output variable assuming the $output variable is declared above
    $output .= '<p><a href="' . $file['file'] . '" download target="_blank"><i class="fa fa-download"></i> '. $file['name'].'</a></p>';
}
//从woocommerce声明$product变量,如果以前声明过,则不需要此变量
全球$产品;
//从产品中获取所有可下载的文件
$files=$product->get_files();
//循环浏览每个可下载的文件
foreach($files作为$file){
//假设上面声明了$output变量,则将带有链接和名称的html存储在$output变量中
$output.='

'; }
然后应该将链接添加到您正在使用的$output变量中,该变量可以是
echo
return

另外,尝试学习基本的php,这并不难,在没有知识的情况下使用php要比学习基础知识困难得多:)