dso15221
2016-09-16 03:52
浏览 109
已采纳

从'woocommerce_email_customer_details'钩子中删除'email_addresses'操作

In WooCommerce, there is a public static class WC_Emails, defined in /woocommerce/includes/class-wc-emails.php.

Within that class, there is a reference to a hook called woocommerce_email_customer_details. To that hook, an action called email_addresses is assigned, which is simply a PHP file that generates some HTML for billing and shipping addresses to be added to email notifications.

add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 );

I am trying to remove that action and can't seem to figure out how to do it.

Here's an example bit of code in my child theme's functions.php that does not work:

add_action( 'init', 'remove_default_addresses');
    function remove_default_addresses() {
    remove_action( 'woocommerce_email_customer_details', 
                   array( 'WC_Emails', 'email_addresses' ), 20);
}

Instead of the init hook there, I have tried wp-head. Since WC_Emails is a static function, the above code is the way the WordPress Codex suggests, as far as using an array() above, instead of just the action name. Regardless, this doesn't work, either (with just the action name):

add_action( 'init', 'remove_default_addresses');
function remove_default_addresses() {
    remove_action( 'woocommerce_email_customer_details', 'email_addresses', 20);
}

20 is the priority on the add_action Woo does, and I also understand that a remove_action() must have the same priority as what the original add_action() had.

No matter what I try, the billing and shipping addresses still appear on the email notifications.

Once that gets working, it will be great! However, there is an additional requirement: This needs to happen only inside code I have for the woocommerce_order_status_pending_to_processing_notification hook in Woo.

In other words, I have other code that fires and generates an email when an order status changes from Pending to Processing (and I have tried my code above with all its variations within that hook as well). I need the billing and shipping addresses to NOT show only in the custom email that is generated.

Any ideas? Thanks so much. :)

图片转代码服务由CSDN问答提供 功能建议

在WooCommerce中,有一个公共静态类 WC_Emails ,在 /中定义 woocommerce / includes / class-wc-emails.php

在该类中,有一个名为 woocommerce_email_customer_details 的钩子的引用。 在该钩子上,分配了一个名为 email_addresses 的动作,它只是一个PHP文件,它生成一些HTML用于计费和发送地址以添加到电子邮件通知中。

  add_action('woocommerce_email_customer_details',array($ this,'email_addresses'),20,3); 
   
 
 

我正在尝试删除该操作, 似乎无法弄清楚如何去做。

这是我的孩子主题的 functions.php 中的一段代码示例,它不起作用:

  add_action('init','remove_default_addresses'); 
 function remove_default_addresses(){
 remove_action('woocommerce_email_customer_details',
 array('WC_Emails','email_addresses')  ,20); 
} 
   
 
 

我尝试了 wp-head init 钩子。 >。 由于 WC_Emails 是一个静态函数,上面的代码就是WordPress Codex建议的方式,只要使用上面的 array(),而不仅仅是动作名称。 无论如何,这也不起作用(仅使用操作名称):

  add_action('init','remove_default_addresses'); 
function remove_default_addresses(){
  remove_action('woocommerce_email_customer_details','email_addresses',20); 
} 
   
 
 

20 add_action的优先级 Woo,我也理解 remove_action()必须具有与原始 add_action()相同的优先级。

无论我尝试什么,帐单和送货地址仍会显示在电子邮件通知中。

一旦它开始工作,它就会很棒! 但是,还有一个额外的要求:这只需要在我对Woo中 woocommerce_order_status_pending_to_processing_notification 挂钩的代码中发生。

换句话说,我还有其他代码 当订单状态从Pending变为Processing时,会触发并生成一封电子邮件(我已经尝试了上面的代码以及该钩子中的所有变体)。 我需要结算和送货地址不会仅显示在生成的自定义电子邮件中。

有任何想法吗? 非常感谢。 :)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drpqxogph15436713 2016-11-18 10:09
    已采纳

    Here is the code:

    add_action( 'woocommerce_email', function ( $email_class ) {
        remove_action( 'woocommerce_email_customer_details', array( $email_class, 'email_addresses' ), 20, 3 );
    });
    

    Source

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题