0

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

2 Answers2

2

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • that did not work. tried with three different themes just to make sure. –  Apr 30 '19 at 19:05
  • @KevinAronsson For me it works on 5 different themes… I always test the code that I publish. – LoicTheAztec Apr 30 '19 at 19:37
  • well, doesn't here on storefront, genesis or astra with clean installs. –  Apr 30 '19 at 22:04
  • Works for me. Try to remove the is_checkout() condition, maybe you're just not on the checkout page really. – Buzut Jun 02 '22 at 08:10
1

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

add_filter( 'wc_add_to_cart_message_html', '__return_false' );
cabral279
  • 97
  • 10