Woocommerce:验证我的帐户编辑页面上的自定义字段 [英] Woocommerce: validate custom fields on my account edit page

查看:25
本文介绍了Woocommerce:验证我的帐户编辑页面上的自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在编辑我的帐户"页面中验证并保存我的自定义字段.我在 woocommerce/myaccount/form-edit-account.php 找到了这个页面的模板.我设法在这个模板文件中添加了我的自定义字段.现在我需要验证它们,如果一切顺利 - 保存用户数据.

I need to validate and save my custom fields in "Edit my account" page. I found template of this page at woocommerce/myaccount/form-edit-account.php. I managed to add my custom fields in this template file. Now I need to validate them and if it's all good - save user data.

在这种情况下我需要使用什么钩子?我可以编辑 class-wc-form-handler.php 但我不想这样做.

What hook do I need to use in this situation? I can edit class-wc-form-handler.php but I don't want to.

谢谢

推荐答案

我发现了一个操作挂钩,可用于验证编辑帐户"页面上的自定义字段或现有字段.
在functions.php中添加以下代码.

I found out an action hook that can be used to validate custom fields or existing fields on Edit Account page.
Add following code in functions.php.

add_action('user_profile_update_errors','wdm_validate_custom_field',10,1);
function wdm_validate_custom_field($args)
{
    if ( isset( $_POST['custom_field'] ) )
    {
        if(strlen($_POST['custom_field'])<6 )
        $args->add( 'error', __( 'Your error message', 'woocommerce' ),'');
    }
}

这篇关于Woocommerce:验证我的帐户编辑页面上的自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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