小编Sha*_*wer的帖子

使用 Hook 在我的帐户页面上验证 Woocommerce 地址更新

我想在通过“我的帐户”页面更新地址时在计费电话上添加验证。

表格位置: http: //www.example.com/my-account/edit-address/billing

我的代码到目前为止如下:-

add_action( "woocommerce_customer_save_address", 'custom_validation'); 

function custom_validation($user_id,$load_address)
{
    if ( $user_id <= 0 )
    {
        return;
    }

    if(isset($_POST['billing_phone']))
    {
        $account_billing_phone   = ! empty( $_POST['billing_phone'] ) ? wc_clean( $_POST['billing_phone'] ) : '';
        $get_user                = wp_get_current_user();
        $user_phone = get_user_meta( $get_user->ID, 'billing_phone', true );
        if(strlen($account_billing_phone) !== 10 )
        {
            wc_add_notice( __( 'Enter a valid 10 digit mobile number', 'woocommerce' ), 'error' );
        }
        elseif($account_billing_phone !== $user_phone)
        {
            $user_exist = get_users(array('meta_value' => array($account_billing_phone)));
            if($user_exist)
            {
                wc_add_notice( __( 'Mobile number already exist.', …
Run Code Online (Sandbox Code Playgroud)

php wordpress woocommerce hook-woocommerce

3
推荐指数
1
解决办法
3446
查看次数

标签 统计

hook-woocommerce ×1

php ×1

woocommerce ×1

wordpress ×1