skip to Main Content

I am using woocommerce_email_attachments dedicated hook to attach items downloadable files to WooCommerce Customer completed order email notification. My problem is that I got forbidden 403, because the hook is taking the file directly from the file URL, from Woocommerce_uploads:

https://website.com/wp-content/uploads/woocommerce_uploads/2021/02/document-for-client-deqwt5.docx

With this, I got 403 forbidden. But if I delete the .htaccess file from woocommerce_uploads everything works fine.

I suspect that if I can make the hook to use the same download path as the user, I won´t get a 403 forbidden response.

Something like:
https://website.com/?download_file=XXX&order=wc_order_zYAt52a4N3sh1&uid=c76cc30b2b37b32ca4615429b283a74fa483c6501f27aa0c108b912870c71c7a&key=1ebcc129-b89c-4f0e-9229-8b0c06734a7b

How could I make the hook use the secure download path insteads of the file URL?

This is the hook I am using, from another answer:

add_filter( 'woocommerce_email_attachments', 'attach_downloadable_files_to_customer_completed_email', 10, 3 );
function attach_downloadable_files_to_customer_completed_email( $attachments, $email_id, $order ) {
    if( isset( $email_id ) && $email_id === 'customer_completed_order' ){
        // Loop through order items
        foreach( $order->get_items() as $item ) {
            $product = $item->get_product(); // The product Object

            if ( $product->is_downloadable() && ( $downloads = $product->get_downloads() ) ) {
                // Loop through product downloads
                foreach( $downloads as $download ) {
                    $attachments[] = $download->get_file();
                }
            }
        }
    }
    return $attachments;
}

2

Answers


  1. Chosen as BEST ANSWER

    The problem is solved:

    • In woocommerce_upload folder
    • Replace the .htaccess content with this:
    order deny,allow
    deny from all
    allow from <your ip or server IP or hosting IP> 
    

  2. Are you lookin for this?

    foreach( $downloads as $download ) {
        $attachments[] = $product->get_file_download_path($download->get_id());
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search