user11391182
user11391182

Reputation:

Remove "Added to cart" and "Cart updated" message on Checkout for WooCommerce

I found the code below online and it works great. It creates a "one page" checkout. Only problem is, the "cart is updated" message on the checkout when changing the quantity of a product. I need to remove it.

Here's the code I'm using to get a "one page" checkout:

// creates a combined cart and checkout page
add_action( 'woocommerce_before_checkout_form', 'one_page_checkout', 5 );
function one_page_checkout() {
if ( is_wc_endpoint_url( 'order-received' ) ) return; ?>
<div class="one-page-checkout-cart"><?php echo do_shortcode('[woocommerce_cart]'); ?></div>
<?php
}

// on empty cart when on checkout, redirect to home page
add_action( 'template_redirect', 'redirect_on_empty_checkout' );
function redirect_on_empty_checkout() {
if ( is_cart() && is_checkout() && 0 == WC()->cart->get_cart_contents_count() && ! is_wc_endpoint_url( 'order-pay' ) && ! is_wc_endpoint_url( 'order-received' ) ) {
wp_safe_redirect( 'shop' );
exit; } }


// removes coupon field form checkout, do not use CSS for this
add_action( 'woocommerce_before_checkout_form', 'remove_checkout_coupon_form_for_one_page_checkout', 9 );
function remove_checkout_coupon_form_for_one_page_checkout(){
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
}

For "cart is updated" message, this is the code that I'm using. It works great on the checkout, but it also removes the "added to cart" message on the product page.

add_filter( 'woocommerce_add_message', 'unset_atc_html_from_one_page_checkout' );
function unset_atc_html_from_one_page_checkout() {
global $woocommerce;
if (is_checkout() ) {
add_filter('woocommerce_add_message', '__return_false');
}}

Kindly help getting the "cart updated" message removed from checkout while keeping the "added to cart" message on the product page.

Upvotes: 0

Views: 1434

Answers (2)

cabral279
cabral279

Reputation: 97

To remove "[Product Name] has been added to your cart."

add_filter( 'wc_add_to_cart_message_html', '__return_false' );

Upvotes: 1

LoicTheAztec
LoicTheAztec

Reputation: 253919

To remove "Cart updated" or "{$product_name} has been added to your cart" messages on your custom checkout page use the following:

add_filter( 'woocommerce_add_message', 'remove_cart_updated_message_from_checkout' );
function remove_cart_updated_message_from_checkout( $message ) {
    if ( is_checkout() && ( strpos($message, 'Cart updated') !== false
    || strpos($message, 'has been added to your cart') !== false ) ) {
        return false;
    }
    return $message;
}

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

Upvotes: 2

Related Questions