2

我对 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 服装订单约翰!”。在电子邮件的正文中,我试图将这个个人作为一个小的感谢信息,但是,当我发送信息时,我使用了钩子:

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

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

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

例如:woocommerce_email_header_customer_processing_order或大意的词?

谢谢

4

1 回答 1

6

要使用钩子添加一些自定义内容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 文件中。

此代码经过测试并且有效

于 2017-01-05T02:58:49.393 回答