2016-06-01 12 views
1

this processを使用してWooCommerce登録にカスタムフィールドを追加しました。 私はこれらのアクションを使用して、マイアカウントの編集ページにそれらが利用可能になってきた2つの間でWooCommerce:マイアカウントの編集ページでカスタムフィールドを検証する

// added custom fields here 
add_action('woocommerce_edit_account_form', 'my_woocommerce_edit_account_form'); 

// saved user meta here 
add_action('woocommerce_save_account_details', 'my_woocommerce_save_account_details'); 

、私は編集する際に、これらのフィールドを検証する必要があります。私はwoocommerce_process_myaccount_field_フィルタ(as mentioned here)を使ってみましたが、うまくいかなかった。変更を保存すると、その内部のコードはトリガされません。

どうすれば検証できますか?
正しいフィルタを使用していますか?
「はい」の場合、なぜ起動しませんか?

ありがとうございました。

+0

どちらがあなたのために働いていましたか?ありがとう – LoicTheAztec

+1

これは: 'woocommerce_save_account_details_errors'です。私はなぜこれがWooCommerceのWeb上のHooksのリファレンスになかったのだろうか。 – sgr12

+0

はい、それは** hookr.io **にあります:[woocommerceはアカウントの詳細をフックに保存します](http://hookr.io/actions/ woocommerce_save_account_details_errors /)とhttps://github.com/woothemes/woocommerce/blob/master/includes/class-wc-form-handler.php#L223 – LoicTheAztec

答えて

4

この2つのフックのいずれかを使用して、カスタムフィールドの検証を試みることができます。

add_action('user_profile_update_errors','wooc_validate_custom_field', 10, 1); 

// or 

add_action('woocommerce_save_account_details_errors','wooc_validate_custom_field', 10, 1); 

// with something like: 

function wooc_validate_custom_field($args) 
{ 
    if (isset($_POST['custom_field'])) // Your custom field 
    { 
     if(strlen($_POST['custom_field'])<4) // condition to be adapted 
     $args->add('error', __('Your error message', 'woocommerce'),''); 
    } 
} 
関連する問題