根据您的具体情况,在短代码/class-wc-shortcode-cart.php我们发现:
wc_add_notice( __( 'Shipping costs updated.', 'woocommerce' ), 'notice' );
这又调用了wc_add_notice()
功能:
...
// Backward compatibility.
if ( 'success' === $notice_type ) {
$message = apply_filters( 'woocommerce_add_message', $message );
}
$message = apply_filters( 'woocommerce_add_' . $notice_type, $message );
...
(此代码部分复制自:包括/wc-notice-functions.php)
所以不要使用woocommerce_add_message
过滤钩你可以使用woocommerce_add_"$notice_type"
过滤钩。
$notice_type
= 通知类型的名称 -错误、成功(默认)或通知。
就你而言,$notice_type
对应于notice。那么只需比较消息,如果足够,我们返回 false:
function filter_woocommerce_add( $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', 10, 1 );
// OR - Use the desired filter, depending on the name of the notice type (default = success)
// add_filter( 'woocommerce_add_error', 'filter_woocommerce_add', 10, 1 );
// add_filter( 'woocommerce_add_success', 'filter_woocommerce_add', 10, 1 );