Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段)
问题描述
之前有人问过类似的问题,我尝试了所有解决方案,但由于某种原因,它们对我不起作用.
我的网站页脚中包含一个迷你 Woocommerce 注册字段,以便人们可以轻松注册.电话字段是必需的,但我想为其设置最小长度以减少输入假号码的人数.
我将以下代码添加到我的functions.php,(我将所有通知都包含在表单中,以便您可以更好地理解)占位符,一切正常,但我无法获得最小长度(设置使用模式"自定义属性)工作.
如果有人能帮我修复它,我将不胜感激.
此表格包含在我网站的页脚中:
Similar questions have been asked before and I tried all the solutions but for some reason they won't work for me.
I have a mini Woocommerce registration field included in the footer of my site so that people can register easily. The phone field is required but I want to set a minimum length to it to reduce the number of people entering fake numbers.
I have the following codes added to my functions.php, (I'm including all the notifications to the form so that you can understand better) the placeholder and everything works but I can't get the minimum length (set using "pattern" custom attribute) to work.
If anyone can help me fix it, it'd be very much appreciated.
This form is included in the footer of my web site: wondercatspopup.com
The code I've added is:
And this is the rest of the functions.php:
Note: Your special registration form located in the footer is something different than WooCommerce checkout fields.
In your code the hook for your validating function text_domain_woo_validate_reg_form_fields()
is just missing. There is also some small errors (corrected)…
The best place to check the submitted data is your validation function and you should also need to add another one for checkout too (instead of using a custom pattern for checkout phone field, that is used to format data).
So all your related code should be:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works
Each time the phone number minimal length will be checked and display this alert (if needed):
这篇关于在 WooCommerce 和电话字段验证问题中添加自定义注册字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!