• Hi Dan,

    I have one more suggestion. I have noticed that the error message that is being printed when you attempt to finish checkout despite no shipping method being available is not replaced with the message configured via your plugin.

    I mean this error message: No shipping method has been selected. Please double check your address, or contact us if you need any help. See https://github.com/woocommerce/woocommerce/blob/4.1.0/includes/class-wc-checkout.php#L829

    I found out that one way how to replace this message is via woocommerce_after_checkout_validation action:

    add_action('woocommerce_after_checkout_validation', function ($data, $errors) use ($message, $escape) {
        $error_messages = $errors->get_error_messages('shipping');
    
        if ($error_messages === array()) {
            return;
        }
    
        $legacy_error_message = __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce'); // As of WC 4.1
        $custom_error_message = $escape ? htmlspecialchars($message, ENT_QUOTES, 'UTF-8') : $message;
    
        $errors->errors['shipping'] = array_map(
            function ($error_message) use ($legacy_error_message, $custom_error_message) {
                // Replace legacy error message with custom error message, keep any other shipping errors untouched.
                return $error_message === $legacy_error_message ? $custom_error_message : $error_message;
            },
            $error_messages
        );
    }, 10, 2);
    

    Would you consider adding this code to your plugin?

    • This topic was modified 4 years, 10 months ago by ?eslav Przywara. Reason: Formatting
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Replace default error notice at checkout as well’ is closed to new replies.