get downloadable links for products in WooCommerce

To get downloadable links for products in WooCommerce using PHP, you can use the following code:

<?php
// Get the current product
$product = wc_get_product();

// Check if the product is downloadable
if ( $product->is_downloadable() ) {
  // Get the downloadable files for the product
  $downloads = $product->get_downloads();

  // Loop through the downloadable files
  foreach ( $downloads as $download ) {
    // Get the download URL and file name
    $download_url = $download['file'];
    $download_name = $download['name'];

    // Output the download link
    echo '<a href="' . $download_url . '">' . $download_name . '</a>';
  }
}
?>


	
	

Leave a Reply