在 woocommerce 结帐页面中验证电话号码 [英] Validate phone number in woocommerce checkout page

查看:24
本文介绍了在 woocommerce 结帐页面中验证电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 woocommerce 的结帐页面中为电话号码添加自定义验证.我该怎么做??

I would like to add custom validation to the phone number in checkout page of woocommerce. How do I do this??

推荐答案

默认 woocommerce 已经有正则表达式验证.最简单的方法是通过 jquery 验证它.

BY default woocommerce already have regular expression validation. The easiest way would be to validate it through jquery.

尽量不要对 woocommerce 核心进行任何更改,因为它们将在下次更新时被覆盖.试试这个代码

Try not to make any changes to the woocommerce core as they will be over ridden on next update. Try this code

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['shipping']['shipping_phone'] = array(
        'label'     => __('Phone', 'woocommerce'),
    'placeholder'   => _x('Phone', 'placeholder', 'woocommerce'),
    'required'  => true,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     return $fields;
}

这篇关于在 woocommerce 结帐页面中验证电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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