2014-04-09 7 views
2

"내 계정 편집"페이지에서 사용자 정의 필드의 유효성을 검사하고 저장해야합니다. 이 페이지의 템플릿은 woocommerce/myaccount/form-edit-account.php입니다. 나는이 템플릿 파일에 사용자 정의 필드를 추가 할 수있었습니다. 이제 나는 그것들을 검증 할 필요가 있으며 그것이 모두 좋은 것이라면 - 사용자 데이터를 저장하십시오.Woocommerce : 내 계정 편집 페이지의 사용자 정의 필드 유효성 확인

이 상황에서 어떤 고리를 사용해야합니까? class-wc-form-handler.php을 편집 할 수는 있지만 원하지 않습니다.

감사

+0

당신이 필터와 액션을 사용하여 필드를 추가 했습니까? http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ – topdown

답변

2

나는 사용자 정의 필드 또는 계정 편집 페이지에서 기존 필드의 유효성을 검사하는 데 사용할 수있는 액션 훅을 발견했다.
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'),''); 
    } 
} 
0

검증이 작업 후크를 사용하여 수행

0

이 시도 woocommerce_save_account_details_errors 할 수 있습니다.

add_filter('woocommerce_process_myaccount_field_{your_custom_field_name}' , 'validate_edit_address'); 
function validate_edit_address() { 

    $variable = $_POST['your_custom_field_name']; 
    if (preg_match("/[ก-๙a-zA-Z]+$/", $variable)){  
     wc_add_notice(__('<strong>Error</strong>'), 'error'); 
    } 
    return $variable ; 
} 

예 :

add_filter('woocommerce_process_myaccount_field_billing_house_number' , 'validate_edit_address'); 
function validate_edit_address() { 

    $variable = $_POST['billing_house_number']; 
    if (preg_match("/[ก-๙a-zA-Z]+$/", $variable)){  
     wc_add_notice(__('<strong>Error</strong>'), 'error'); 
    } 
    return $variable ; 
} 
관련 문제