如何删除 WooCommerce 中的“运费更新”消息

问题描述

我正在使用它来删除 Woocommerce 中的“购物车已更新”消息:

add_filter( 'woocommerce_add_message','__return_false');

但仍会显示“运费已更新”消息。如何删除此消息?

解决方法

shortcodes/class-wc-shortcode-cart.php我们找到

wc_add_notice( __( 'Shipping costs updated.','woocommerce' ),'notice' );

includes/wc-notice-functions.php中我们发现,在wc_add_notice函数中

// Backward compatibility.
if ( 'success' === $notice_type ) {
    $message = apply_filters( 'woocommerce_add_message',$message );
}

$message = apply_filters( 'woocommerce_add_' . $notice_type,$message );

因此,您可以使用 woocommerce_add_message 过滤器钩子代替 woocommerce_add_"$notice_type" 过滤器钩子。然后您将比较通知消息,如果这足够了,我们将返回 false。


所以你得到:

function filter_woocommerce_add_notice ( $message ) {
    // Equal to (Must be exactly the same).
    // If the message is displayed in another language,adjust where necessary!
    if ( $message == 'Shipping costs updated.' ) {
        return false;
    }   
    
    return $message;
}
add_filter( 'woocommerce_add_notice','filter_woocommerce_add_notice',10,1 );

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...