首页 > 解决方案 > 从帐户内容中删除 WooCommerce 消息

问题描述

我目前正在尝试使用以下代码行从 WooCommerce 帐户中删除所有消息:

remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );

可悲的是,消息的包装器仍然存在:

<div class="woocommerce-notices-wrapper">lol</div>

我在lol显示包装器的函数中添加了一个,这是我要删除的正确函数。不知道为什么它不起作用...

标签: phpwordpresswoocommerce

解决方案


如果您的活动主题使用默认的 woocommerce 模板和 myaccount 页面的挂钩,则添加以下代码片段以实现上述目的 -

function modify_wc_hooks() {
    // remove all wc my account's notices wrapper
    remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
    remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
    remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
    remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
    remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
}
add_action( 'init', 'modify_wc_hooks', 99 );

代码转到您的活动主题的functions.php


推荐阅读