简体   繁体   English

Woocommerce 可下载产品作为 email 附件 - 403 禁止

[英]Woocommerce downloadable product as email attachment - 403 forbidden

I am using woocommerce_email_attachments dedicated hook to attach items downloadable files to WooCommerce Customer completed order email notification.我正在使用woocommerce_email_attachments专用挂钩将项目可下载文件附加到 WooCommerce 客户完成订单 email 通知。 My problem is that I got forbidden 403, because the hook is taking the file directly from the file URL, from Woocommerce_uploads:我的问题是我被禁止 403,因为钩子直接从 Woocommerce_uploads 的文件 URL 中获取文件:

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

With this, I got 403 forbidden.有了这个,我得到了 403 禁止。 But if I delete the .htaccess file from woocommerce_uploads everything works fine.但是,如果我从 woocommerce_uploads 中删除 .htaccess 文件,一切正常。

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.我怀疑如果我可以使钩子使用与用户相同的下载路径,我将不会得到 403 禁止响应。

Something like: https://website.com/?download_file=XXX&order=wc_order_zYAt52a4N3sh1&uid=c76cc30b2b37b32ca4615429b283a74fa483c6501f27aa0c108b912870c71c7a&key=1ebcc129-b89c-4f0e-9229-8b0c06734a7b 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?如何让钩子使用安全下载路径而不是文件 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;
}

Are you lookin for this?你在找这个吗?

foreach( $downloads as $download ) {
    $attachments[] = $product->get_file_download_path($download->get_id());
}

The problem is solved:问题已经解决了:

  • In woocommerce_upload folder在 woocommerce_upload 文件夹中
  • Replace the .htaccess content with this:将 .htaccess 内容替换为:
order deny,allow
deny from all
allow from <your ip or server IP or hosting IP> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM