【问题标题】:Change product download link to custom link by admin管理员将产品下载链接更改为自定义链接
【发布时间】:2021-06-19 16:55:01
【问题描述】:

我正在尝试将产品下载 url 更改为管理员输入的自定义 url。我已经使用下面的代码在单个产品页面上完成了此操作。但它在“下载”页面中不起作用。我尝试更新 order_download.php 文件中的代码,但没有响应。

    // 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(); 
echo "<style>.elementor-widget-jet-single-add-to-cart > div > div > form{display:none;}</style>";
//Loop through each downloadable file
foreach( $files as $file ) {
    $new_url = $file['file'];
    //store the html with link and name in $output variable assuming the $output variable is declared above
   $links_html .= "<a class='{$classes}' href='{$new_url}' data-key='{$key}' target='_blank' data-product-id='{$id}'>{$name}</a>";
}

【问题讨论】:

    标签: php wordpress woocommerce plugins


    【解决方案1】:

    现在解决了,我所做的只是将 $file['file'] 更改为 $file["file"]['file']

    【讨论】:

      【解决方案2】:

      初始化顶部的 $links_html。

      $links_html = '';
      foreach( $files as $file ) {
          $new_url = $file['file'];
          $links_html .= '<a class="'.$classes.'" href="'.$new_url.'" data-key="'.$key.'" target='_blank' data-product-id="'.$id.'">'.$name.'</a>';
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-23
        • 1970-01-01
        • 2019-06-25
        • 2018-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多