5

我正在研究由其他一些德国开发人员为 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 );

我怎样才能做到这一点?

4

1 回答 1

9

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

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

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


参考 :

于 2016-09-28T10:56:38.460 回答