skip to Main Content

I’m facing an issue while trying to customize the error message displayed in WooCommerce checkout when no shipping method is available

enter image description here

I’ve made multiple attempts using various hooks, but I haven’t been able to achieve the desired result. Here’s a rundown of what I’ve tried along with the corresponding code snippets:

Attempt 1: Using woocommerce_checkout_no_shipping_available_notice

function custom_change_shipping_error_message( $message ) {
    return 'We are not available at this location at this moment. Please change the date and try again or call our customer support.';
}
add_filter( 'woocommerce_checkout_no_shipping_available_notice', 'custom_change_shipping_error_message' );

Attempt 2: Using woocommerce_no_shipping_available_html

function custom_change_shipping_error_message( $message ) {
    return 'We are not available at this location at this moment. Please change the date and try again or call our customer support.';
}
add_filter( 'woocommerce_no_shipping_available_html', 'custom_change_shipping_error_message' );

Attempt 3: Using 'woocommerce_checkout_error

function custom_change_shipping_error_message( $message, $error ) {
    if ( is_array( $error ) && in_array( 'no_shipping_method_selected', $error ) ) {
        $message = 'We are not available at this location at this moment. Please change the date and try again or call our customer support.';
    }
    return $message;
}

add_filter( 'woocommerce_checkout_error', 'custom_change_shipping_error_message', 10, 2 );

Despite these efforts, I’m still encountering the default error message, and none of these changes seem to be taking effect. Can anyone provide guidance on what I might be missing or suggest an alternative approach to successfully customize the error message in the WooCommerce checkout process? Your assistance would be greatly appreciated!

2

Answers


  1. One option would be to use the woocommerce_add_error filter and check the error text.

    Note that this approach will only work while the error message stays the same, you might encounter issues on for example multilingual sites with translated error messages.

    function change_no_shipping_method_error_text( $error ) {
        if( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.' == $error ) {
            $error = 'New error message';
        }
        return $error;
    }
    add_filter( 'woocommerce_add_error', 'change_no_shipping_method_error_text' );
    
    Login or Signup to reply.
  2. thanks for this update. I want to ask if there’s a way to change the text for shipping on checkout page below total sub-total?
    There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.
    It says this right now, ,can we change it somehow?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search