duanhe3393 2019-08-02 14:45
浏览 25

WooCommerce订阅多次取消电子邮件

When a Customer cancels a subscription, I send the cancellation email to both the Admin and the customer

/* Send email to customer on cancelled order in WooCommerce */
add_action('woocommerce_subscription_status_updated', 'send_custom_email_notifications', 10, 3 );
function send_custom_email_notifications( $subscription, $new_status, $old_status ){
    if ( $new_status == 'cancelled' || $new_status == 'pending-cancel' ){
        $customer_email = $subscription->get_billing_email();
        $userid = $subscription->get_user_id();
        $wc_emails = WC()->mailer()->get_emails();
        $wc_emails['WC_Email_Cancelled_Order']->recipient .= ',' . $customer_email;
        $wc_emails['WC_Email_Cancelled_Order']->trigger( $orderid );
    } 
}

I need to send the Customer a different, custom email using an email template I created. I'm thinking I need to replace the code above with something like this

$wc_emails['WC_Email_Custom_Template']->$customer_email;
$wc_emails['WC_Email_Custom_Template']->trigger( $orderid );

but haven't found it yet.

UPDATE

This code will send two separate emails when a customer cancels a subscription; one to the email address that is the recipient (WooCommerce, Settings, Email, Cancelled Subscription, Recipient) and one to the customer. The custom customer email is saved to the theme's WooCommerce, Email folder and will override the WooCommerce default template file.

But the email doesn't get sent to the customer when the Admin cancels the subscription from the Edit Order screen.

/* Send email to customer on cancelled order in WooCommerce */
add_action('woocommerce_subscription_status_updated', 'send_custom_email_notifications', 10, 3 );
function send_custom_email_notifications( $subscription, $new_status, $old_status ){

    if ( $new_status == 'cancelled' || $new_status == 'pending-cancel' ){
        $customer_email = $subscription->get_billing_email();
        $orderid = $subscription->get_order_number();
        $wc_emails = WC()->mailer()->get_emails();

        // Send email to both admin and customer
        // $wc_emails['WC_Email_Cancelled_Order']->recipient .= ',' . $customer_email;

        // Send email to admin only
        $wc_emails['WC_Email_Cancelled_Order']->recipient;
        $wc_emails['WC_Email_Cancelled_Order']->trigger( $orderid );

        // Send email to customer only
        $mailer = WC()->mailer();
        $subject = __('Subscription Cancelled', 'custom');
        $content = get_cancelled_subscription_content( $subscription, $subject, $mailer );
        $headers = "Content-Type: text/html
";

        $mailer->send( $customer_email, $subject, $content, $headers );        

    } 
}

function get_cancelled_subscription_content( $subscription, $heading = false, $mailer ) {

    $template = 'woocommerce/emails/cancelled-subscription.php';

    return wc_get_template_html( $template, array(
        'order'         => $subscription,
        'email_heading' => $heading,
        'sent_to_admin' => true,
        'plain_text'    => false,
        'email'         => $mailer
    ) );
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录