在Woocommerce结帐页面中设置唯一的验证错误通知 [英] Set a unique validation error notice in Woocommerce checkout page

查看:54
本文介绍了在Woocommerce结帐页面中设置唯一的验证错误通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Woocommerce结帐页面显示必填字段为空的单个错误。通常,如果所有字段为空,则将显示这些空字段的所有错误:

-名字是必填字段

-姓氏是必填字段

-街道地址是必填字段

-城镇/城市是必填字段

等等……

Woocommerce checkout page shows individual error if the required fields are empty. Normally, if all fields are empty, all errors for those empty fields will be shown:
- First name is a required field
- Last name is a required field
- Street address is a required field
- Town / City is a required field
and so on…

如果所有必填字段为空,是否可能仅显示一个错误?如错误:所有字段为空。请填写所有必填字段以下订单。

Is it possible to show only one error if all the required fields are empty? Like "ERROR: All fields are empty. Please fill in all required fields to place order." How to achieve this?

结帐页面

推荐答案

要在Woocommerce结帐页面中设置唯一的验证错误通知,您将使用以下代码:(代码主要来自您的上一个问题

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.' );
    }
}

代码会出现在您活跃孩子的function.php文件中主题(活动主题)。经过测试并有效。

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

相关: 在Woocommerce我的帐户地址和帐户详细信息中设置唯一的验证错误通知

这篇关于在Woocommerce结帐页面中设置唯一的验证错误通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆