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


Removing customer details and addresses from email notification templates

我正在为woocommerce创建一个主题,由其他一些德国开发人员构建。我已经创建了我的子主题,并使用子主题的functions.php来更改网站的功能。

当客户订购产品时,他会收到一封包含订单表、客户信息、账单地址和客户发货信息的电子邮件。我想删除表下的所有内容,并添加我自己的文本(客户信息+账单、送货和提货地址)。

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

到目前为止,我试着这样做:

remove_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); 
从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 );

我怎样才能做到这一点?

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

/**
 * @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核心文件的一些研究和一些测试,我已经成功地从通知电子邮件中删除了客户详细信息,账单和送货地址。

代码如下:

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

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


引用:

    类wc_email customer_details()方法
  • 类wc_email email_addresses()方法