从电子邮件通知模板中删除客户详细信息和地址 [英] Removing customer details and addresses from email notification templates
问题描述
我正在研究一个由woolet创建的主题,该主题是由其他德国开发商开发的.我已经创建了子主题并使用子主题的functions.php来更改网站的功能.
I am working on a theme created for woocommerce, built by some other German developer. I have created my child theme and using child theme's functions.php to make changes to functionality of the website.
客户订购产品时,会收到一封电子邮件,其中包含订单表,客户信息,账单地址和客户运输.我想删除表格下方的所有内容,并添加自己的文字(客户信息+帐单,送货和提货地址).
When a customer orders a product, he receives an email with order table, customer information and billing address and customer shipping. I want to remove everything below the table and add my own text (customer info + billing, shipping and pick up address as well).
我已经在发送给客户的电子邮件中的订单表下方添加了自己的文本,但是我无法删除默认情况下在自定义添加的文本下方显示的信息.我发现该钩子负责获取并显示数据为 woocommerce_email_order_meta
,但我不知道如何删除或阻止其执行.我不想在模板文件中进行更改,我想通过钩子来完成所有操作.
I have added my own text right below the order table in email that goes to customer, however I am unable to delete the information that shows by default below my custom added text. I found the hook responsible for fetching and showing that data is woocommerce_email_order_meta
, but I don't know how to remove it or prevent it from executing. I don't want to make changes in the template files, I want to do it all by hooks.
到目前为止,我已经尝试过这样做:
So far I have tried doing it like this:
remove_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
我点击了以下链接:从电子邮件中删除订单信息部分中的woocommerce模板,并且也尝试了以下代码,但不起作用.
I followed the link: Delete order info section from email template in woocommerce and tried the following code as well, but didn't work.
function so_39251827_remove_order_details( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer(); // get the instance of the WC_Emails class
remove_action( 'woocommerce_email_order_details', array( $mailer, 'order_details' ), 10, 4 );
}
add_action( 'woocommerce_email_order_details', 'so_39251827_remove_order_details', 5, 4 );
我该如何实现?
推荐答案
说明-在所有电子邮件通知模板中,您都具有以下内容:
Explanations - In all email notification templates you have this:
/**
* @hooked WC_Emails::customer_details() Shows customer details
* @hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
在对WooCommerce核心文件进行了一些研究并进行了一些测试之后,我已根据需要从通知电子邮件中成功删除了客户详细信息,帐单和送货地址.
After some research in WooCommerce core files and some test, I have removed successfully the customer details, the billing and shipping address from notification emails as you wished.
以下是代码:
add_action( 'woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4 );
function removing_customer_details_in_emails( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'customer_details' ), 10 );
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20 );
}
此代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.
此代码已经过测试,功能齐全.
This code is tested and fully functional.
参考文献:
这篇关于从电子邮件通知模板中删除客户详细信息和地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!