сначала вы должны создать плагин и обратиться к этому хуку
, а код выглядит так
//to add the form
function add_age_verification() {
?>
<p class="form-row form-row-first">
<label for="reg_age_verification" class="woocommerce-form__label woocommerce-form__label-for-checkbox"><?php _e( 'age verification', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox" name="age_verification" id="reg_age_verification" value="<?php if ( ! empty( $_POST['age_verification'] ) ) esc_attr_e( $_POST['age_verification'] ); ?>" />
</p>
<div class="clear"></div>
<?php
}
// to validate the form
function validate_age_verification( $errors, $username, $email ) {
if ( isset( $_POST['age_verification'] ) && empty( $_POST['age_verification'] ) ) {
$errors->add( 'age_verification_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
}
return $errors;
}
// to save the form into user meta age_verification
function age_verification_save( $customer_id ) {
if ( isset( $_POST['age_verification'] ) ) {
update_user_meta( $customer_id, 'age_verification', sanitize_text_field( $_POST['age_verification'] ) );
}
}
add_action( 'woocommerce_register_form', 'add_age_verification' );
add_filter( 'woocommerce_registration_errors', 'validate_age_verification', 10, 3 );
add_action( 'woocommerce_created_customer', 'age_verification_save' );