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

≯℡__Kan透↙ 提交于 2019-12-08 13:15:28

To replace all fields validation errors by a unique custom one from Account Billing and Shipping Address, and also Account details, you will use the following hooked function that uses two validation hooks:

add_action( 'woocommerce_save_account_details_errors', 'account_validation_unique_error', 9999 ); // Details
add_action( 'woocommerce_after_save_address_validation', 'account_validation_unique_error', 9999 ); // Adresses
function account_validation_unique_error(){
    $notices = WC()->session->get( 'wc_notices' ); // Get Woocommerce notices from session

    // if any validation errors
    if( $notices && isset( $notices['error'] ) ) {

        // remove all of them
        WC()->session->__unset( 'wc_notices' );

        // Add one custom one instead
        wc_add_notice( __( 'Please fill in all required fields…', 'woocommerce' ), 'error' );
    }
}

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 checkout page

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