skip to Main Content

On the template for order-downloads.php there is reference to the download file delivered for the order. But the reference that it uses produces an encrypted string rather than show the actual url.

%s = $download['download_url'];

In my case the download link will be a link that needs to be bookmarked, so I need the plain url. Can I instead use something like

$download = $order -> download_file();

and if so, what to use?

For testing I tried this code…

$testip = "";
if (!empty($_SERVER['REMOTE_ADDR'])) {
            $drmip = $_SERVER['REMOTE_ADDR'];
        }

        if $testip = "136.220.152.221" {

            $testinvoice = $order->get_order_number();
            $testemail = $order->get_billing_email();
            $testproduct = $order->get_items();

            if(strstr($testproduct,"DDD")) {
                $testdownload = $order->get_downloadable_items()[0]['download_url'];
                echo "<script>alert('ID = " . $testinvoice . " nEmail = " . $testemail . " nURL = " . $testdownload . "')</script>";  
            }

        }

But I am getting an error "critical error on page"

2

Answers


  1. If you have only one possible download by order, you can use the following (that gets the first downloadable item):

    $download      = reset($downloads); // Get first download item
    
    $product = wc_get_product($download['product_id']);
    $product_downloads = $product->get_downloads();
    $product_download  = reset($product_downloads);
    $download_link     = $product_download->get_file();
    
    $order         = wc_get_order( $download['order_id'] );
    $order_number  = $order->get_order_number();
    $billing_email = $order->get_billing_email();
    $customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
    
    // Test output
    print_r('<pre>ID = ' . $order_number . ' <br>Customer name = ' . $customer_name . ' <br>Email = ' . $billing_email . ' <br>URL = ' . $download_link . '</pre>');
    

    Tested and works.

    Login or Signup to reply.
  2. The solution is perfect, but I would also like to get the URLs if there are several product downloads on the page.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search