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.
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
The problem is solved:
Are you lookin for this?