Change product download link to custom link by admin

I'm trying to change the product download url to the custom url that was input by admin. I've done this on a single product page using the code below. But it is not working in the Downloads page. I tried updating the code in order_download.php file but it's not responding.

    // 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>";

2 answers

  • answered 2021-06-19 17:43 cbrr09

    Initialize the $links_html at the top.

    $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>';

  • answered 2021-06-19 18:09 Iwalewa Fawaz

    Resolved now, all I did was change $file['file'] to $file["file"]['file']