【问题标题】:Customizing customer processing emails notification in WooCommerce在 WooCommerce 中自定义客户处理电子邮件通知
【发布时间】:2017-05-19 08:37:53
【问题描述】:

我对 WordPress 非常陌生,并且使用 WooCommerce 创建了一个电子商务商店。

客户下订单后,我会收到一封电子邮件,客户也会收到一封电子邮件 - 一封让我说出他们订购的内容,另一封作为感谢电子邮件发给他们。

在这封感谢邮件中,在我的 functions.php 文件中,我学会了更改标题的主题以包含他们的名字,例如:

//add the first name of the person to the person getting the reciept in the subject of the email. 
add_filter('woocommerce_email_subject_customer_processing_order','UEBC_change_processing_email_subject', 10, 2);

function UEBC_change_processing_email_subject( $subject, $order ) {
global $woocommerce;
$subject = 'Thanks for your ' . get_bloginfo( 'name', 'display' ) . ' Order, '.$order->billing_first_name .'!';
return $subject;
}

上面的代码 sn-p 可以正常工作,并且只显示给客户,而不显示给我。例如“感谢您订购 ABCD Clothes 订购 John!”。 在电子邮件的正文中,我试图将此作为个人的感谢信息,但是,当我发送信息时,我使用的是钩子:

add_action( 'woocommerce_email_before_order_table', 'custom_add_content', 20,1 );

我知道,由于我使用了woocommerce_email_before_order_table 钩子,自定义函数将在电子邮件正文中发送给客户和我自己。

我想知道,Woocommerce 是否提供了一个挂钩,以便仅在电子邮件正文中将自定义功能发送给客户?

例如:woocommerce_email_header_customer_processing_order 或类似的词?

谢谢

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    要使用 woocommerce_email_before_order_table 钩子添加一些自定义内容并仅针对客户“处理订单”电子邮件通知,您应该尝试以下操作:

    add_action( 'woocommerce_email_before_order_table', 'custom_content_to_processing_customer_email', 10, 4 );
    function custom_content_to_processing_customer_email( $order, $sent_to_admin, $plain_text, $email ) {
    
        if( 'customer_processing_order' == $email->id ){
    
            // Set here as you want your custom content (for customers and email notification related to processing orders only)
            echo '<p class="some-class">Here goes your custom content… </p>';
    
        }
    
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件中。或者也可以在任何插件 php 文件中。

    此代码已经过测试并且可以工作

    【讨论】:

    • 太棒了,谢谢你成功了。出于好奇,当只使用 $email 时,在函数中包含所有这 4 个参数的目的是什么?
    • 由于$email 是第四个也是最后一个参数,您无法删除其他参数,您可能需要在未来添加更多条件或基于代码关于其他论点(尤其是第一个论点)......最重要的是这对你有用吗?
    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多