Woocommerce 사용자 계정 등록 양식에 일부 사용자 정의 필드를 추가하려고합니다.
이름과 성을 성공적으로 추가했습니다. T & C 계약 확인란을 추가하려고합니다. 선택하지 않으면 사용자가 등록을 계속할 수 없습니다.
유효성 확인 작업을 수행 할 수 없도록 올바르게 표시 할 수있었습니다. 내가 뭘 잘못 했니?
Woocommerce 계정 등록에서 확인란을 선택하지 않은 경우 오류가 발생합니다.
추신. 알다시피 페이지를 다시로드 할 필요없이 이러한 수표를 실시간으로 사용할 수 있습니까?
감사
내가 사용한 코드 :
add_action('woocommerce_register_form_start', 'cbi_custom_woo_account_registration');
function cbi_custom_woo_account_registration() {
?>
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide first">
<label for="reg_billing_first_name"><?php _e('First name', 'custom-cbi-parts'); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_first_name" id="reg_billing_first_name" value="<?php if (! empty($_POST['billing_first_name'])) esc_attr_e($_POST['billing_first_name']); ?>" />
</p>
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
<label for="reg_billing_last_name"><?php _e('Last name', 'custom-cbi-parts'); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_last_name" id="reg_billing_last_name" value="<?php if (! empty($_POST['billing_last_name'])) esc_attr_e($_POST['billing_last_name']); ?>" />
</p>
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
<label for="accept_terms"><?php _e('I agree TeC', 'custom-cbi-parts'); ?> <span class="required">*</span></label>
<input type="checkbox" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="accept_terms" id="accept_terms" value="<?php if (! empty($_POST['accept_terms'])) esc_attr_e($_POST['accept_terms']); ?>" />
</p>
<div class="clear"></div>
<?php
}
// 2. VALIDATE FIELDS
add_filter('woocommerce_registration_errors', 'cbi_validate_custom_reg_fields', 10, 3);
function cbi_validate_custom_reg_fields($errors, $username, $email) {
if (isset($_POST['billing_first_name']) && empty($_POST['billing_first_name'])) {
$errors->add('billing_first_name_error', __('First name is required!', 'custom-cbi-parts'));
}
if (isset($_POST['billing_last_name']) && empty($_POST['billing_last_name'])) {
$errors->add('billing_last_name_error', __('Last name is required!.', 'custom-cbi-parts'));
}
if (isset($_POST['accept_terms']) && $_POST['accept_terms'] == 0) {
$errors->add('accept_terms_error', __('You must accept Terms and Conditions!.', 'custom-cbi-parts'));
}
return $errors;
}
WooCommerce는 기본적으로 T & C 확인란을 제공합니다. 왜 대신 사용하지 않습니까? –