Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

php - Hide Added to Cart message in Woocommerce

I want to remove the "xx product has been added to your cart" message from the top of my checkout page.

How can I do that?

There was a suggestion by someone (link below), but it didn't work for me.

Remove/Hide Woocommerce Added to Cart Message but Keep/Display Coupon Applied Message

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update for Woocommerce 3+

The hook wc_add_to_cart_message is deprecated and replaced by wc_add_to_cart_message_html. You can use the following (compact effective way):

add_filter( 'wc_add_to_cart_message_html', '__return_false' );

Or the normal way:

add_filter( 'wc_add_to_cart_message_html', 'empty_wc_add_to_cart_message');
function empty_wc_add_to_cart_message( $message, $products ) {?
    return '';?
};?

Before Woocommerce 3, use this:

Removing only the message (pasting it to your function.php file inside your active child theme or theme). This function will return an empty message:

add_filter( 'wc_add_to_cart_message', 'empty_wc_add_to_cart_message', 10, 2 );
function empty_wc_add_to_cart_message( $message, $product_id ) {?
    return '';?
};?

Code goes in function.php file of your active child theme (or active theme).

Note: wc_add_to_cart_message replace deprecated hook woocommerce_add_to_cart_message.

(UPDATED)

CSS: Removing top message box on checkout page (add this css rule to the style.css file located inside your active child theme or theme):

.woocommerce-checkout .woocommerce .woocommerce-message {
    display:none !important;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...