Set a unique validation error notice in Woocommerce checkout page

◇◆丶佛笑我妖孽 提交于 2019-12-01 01:41:31

To set a unique validation error notice in Woocommerce checkout page you will use the following: (code is mainly from your last question and useful to the community. Just changed to the official function arguments code)

add_action( 'woocommerce_after_checkout_validation', 'checkout_validation_unique_error', 9999, 2 );
function checkout_validation_unique_error( $data, $errors ){
    // Check for any validation errors
    if( ! empty( $errors->get_error_codes() ) ) {

        // Remove all validation errors
        foreach( $errors->get_error_codes() as $code ) {
            $errors->remove( $code );
        }

        // Add a unique custom one
        $errors->add( 'validation', 'Please fill in all required fields to place order.' );
    }
}

Code goes in function.php file of your active child theme (active theme). Tested and works.

Related: Set a unique validation error notice in Woocommerce My Account Addresses and Account Details

You would need to disable the current error checking and write custom javascript for the checkout page that would put all the errors in a single message.

There's no native WooCommerce functionality that would accomplish this.

To remove validation, go to your checkout.php template and remove the required attribute from the html fields.

Checkout this link on how to add HTML and javascript to the checkout page.

hHi, you can remove validation from checkout fields and add yours:

Here is the hook:

add_filter( 'woocommerce_default_address_fields' , 'filter_default_address_fields', 20, 1 );

for more, you can go to

therichpost

Its normally show when you press the checkout button. but if you watch it when page load. then maybe it's come by woocommerce bugs. you should update woocommerce plugin. I hope this error would be gone when you will update the plugin.

But after that, if you are facing the same issue contact me. I will look at it.

thank you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!