2016-09-28 59 views
2

我正在致力于为其他一些德国开发人员构建的woocommerce创建的主题。我创建了我的子主题,并使用子主题的functions.php来更改网站的功能。从电子邮件通知模板中删除客户详细信息和地址

当客户订购产品时,他会收到一封电子邮件,其中包含订单表,客户信息和账单地址以及客户送货。 我想删除表格下方的所有内容并添加我自己的文本(客户信息+结算,运输和取件地址)。

我已将自己的文本添加到发送给客户的电子邮件中的订单表下方,但是我无法删除默认情况下在我的自定义添加文本下方显示的信息。我发现钩子负责提取和显示数据是woocommerce_email_order_meta,但我不知道如何删除它或阻止它执行。我不想在模板文件中进行更改,我想通过挂钩来完成。

到目前为止,我已经尝试做这样的:

remove_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); 

我跟着链接:Delete order info section from email template in woocommerce和尝试下面的代码为好,但没有奏效

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); 

我该如何做到这一点?

感谢

回答

6

说明 - 在所有电子邮件通知模板,你有这样的:

/** 
* @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核心文件和一些测试后,我已经成功地去掉了客户的详细信息,计费并根据您的意愿通过电子邮件收件地址。

下面是代码:

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, 4); 
    remove_action('woocommerce_email_customer_details', array($mailer, 'email_addresses'), 20, 4); 
} 
add_action('woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4); 

此代码放在你的活跃儿童主题(或主题)的function.php文件或也以任何插件文件。

此代码已经过测试并且功能完整。


参考文献:

+0

哇!它正在工作!非常感谢你!愿上帝保佑你! – Yogie

+0

LoicTheAztec再次感谢您的帮助,我可以成功完成该项目。但现在我想学习,你是如何达到这个目标的?你究竟做了什么研究?你是怎么知道它是'woocommerce_email_customer_details'钩子而不是'woocommerce_email_order_meta'?然后你怎么找到'array($ mailer,'customer_details')'参数?你是怎么找到'WC() - > mailer()'做的? 请建议,我可以在哪里学习所有这些在门外术语,我是非常新的woocommerce。谢谢!! – Yogie

相关问题