Skip to content
Advertisement

remove_action wc_empty_cart_message not working in WooCommerce

I would like to REMOVE completely the wc_empty_cart_message. My site has no cart. and when the item is removed from checkout the user is redirected to the home page. But then upon browsing to a shop page, the message “your cart is not available whilst your checkout is empty” appears and is completely unnecessary.

I have seen many of questions/answers about how to change the message to something else (I tried some of them which also did not seem to work).

I tried this which seems to be the right thing to do, but for some reason it does not make any visible change on my website.

remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

Is there any way to check which hook is creating the message from the front-end? Or any way how I can see what is overruling this command from executing?

Advertisement

Answer

To remove the “Your cart is currently empty” message, use:

function action_woocommerce_cart_is_empty() {
    // Remove
    remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );  
}
add_action( 'woocommerce_cart_is_empty', 'action_woocommerce_cart_is_empty', 9, 0 );

Where the remove_action in an add_action with a lower priority number (9)


To remove the “Checkout is not available whilst your cart is empty” message, use:

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 == 'Checkout is not available whilst your cart is empty.' ) {
        return false;
    }   
    
    return $message;
}
add_filter( 'woocommerce_add_notice', 'filter_woocommerce_add_notice', 10, 1 );
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement