What code should I add infunctions.php
to remove "Cannot checkout when cart is empty". Notifications in Woocommerce.
I found the code responsible for displaying this message in includes/wc-template-functions.php.
// When on the checkout with an empty cart, redirect to cart page. if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) { wc_add_notice( __( 'Checkout is not available whilst your cart is empty.', 'woocommerce' ), 'notice' ); wp_safe_redirect( wc_get_cart_url() ); exit; }
Overwriting the core files is not an option, any suggestions?
You can use the
woocommerce_checkout_redirect_empty_cart
filter hook. Since the message will only be displayed if this condition is trueAnother option is to use the
woocommerce_add_notice
filter hook that returns false if the message matches