如何在WooCommerce中通过电子邮件发送购买的数字产品 [英] How to send purchased digital products via e-mail in WooCommerce

查看:72
本文介绍了如何在WooCommerce中通过电子邮件发送购买的数字产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出售一个.doc文件文件.用户付款后,该文档文件应发送到其电子邮件地址,而不是像默认情况下那样直接下载.我怎样才能做到这一点?这将是一个可下载的doc文件产品,将通过电子邮件发送到其电子邮件地址

I want to sell a .doc file document. when a user have paid, the doc file should be send to his email address and not directly download like it by default does. how can I do that? it will be a downloadable doc file product that will be emailed to their email address

推荐答案

使用 woocommerce_email_attachments 专用钩子,您可以将项目可下载文件附加到WooCommerce客户已完成的订单电子邮件通知,如下所示:

Using woocommerce_email_attachments dedicated hook, you can attach items downloadable files to WooCommerce Customer completed order email notification as follow:

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;
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

要使其适用于客户处理订单通知,请替换:

To make it work on Customer processing order notification, replace:

if( isset( $email_id ) && $email_id === 'customer_completed_order' ){

作者:

if( isset( $email_id ) && $email_id === 'customer_processing_order' ){


相关答案:


Related answers:

这篇关于如何在WooCommerce中通过电子邮件发送购买的数字产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆