php - 在 WooCommerce 中自定义客户处理电子邮件通知

标签 php wordpress woocommerce orders email-notifications

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

上面的代码片段工作正常,并且仅显示给客户,而不显示给我。例如“感谢您订购 ABCD 衣服订单约翰!”。 在电子邮件正文中,我试图将其作为一条简短的感谢消息,但是,当我发送消息时,我使用了钩子(Hook):

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

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

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

例如:woocommerce_email_header_customer_processing_order 或类似的文字?

谢谢

最佳答案

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

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 文件中。

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

关于php - 在 WooCommerce 中自定义客户处理电子邮件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41474248/

相关文章:

javascript - 链接悬停故障 - 基本 UL 链接使页面在悬停时跳转?

css - Wordpress 子菜单在悬停时消失

php - 如何在 WooCommerce 上设置 Paypal?

wordpress - 如何禁用 woocommerce 的购物车功能?

php - WooCommerce 购物车 - 动态价格变量传递到自定义价格 Hook

php - 如何使用 facebook graph api 让 friend 参与?

从 Windows 移植到 Linux 时,PHP 对 SQL Server 存储过程的调用不起作用

php - 如何在php中从mysql数据库检索视频路径并像youtube一样显示视频?

php - wordpress postmeta 自定义查询问题

php - 非常非常慢的查询。我该如何改进它?