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. :)

  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面