Redirect the checkout page and display a message on the cart page if the cart is empty in WooCommerce

Redirect the checkout page and display a message on the cart page if the cart is empty in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

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 );