从电子邮件通知模板中删除客户详细信息和地

时间:2016-09-28 09:22:02

标签: php wordpress woocommerce orders hook-woocommerce

我正在研究为其他德国开发商建造的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 );

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:8)

说明 - 在所有电子邮件通知模板中都有:

/**
 * @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文件中或任何插件文件中。

此代码经过测试且功能齐全。

参考文献:

相关问题