# Require Age Confirmation When Registering

> Adds a required "I am at least 16 years old" checkbox to the WordPress and WooCommerce registration forms, since many privacy laws do not allow children to consent on their own.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: registration, gdpr, consent
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-age-confirmation-on-registration/

## Code

```php
// Minimum age shown in the checkbox label.
$wpide_min_age = 16;

$wpide_age_field = function () use ( $wpide_min_age ) {
    printf(
        '<p class="form-row"><label for="wpide-age-ok"><input type="checkbox" name="wpide_age_ok" id="wpide-age-ok" value="1" required> %s</label></p>',
        esc_html( sprintf( 'I confirm that I am at least %d years old.', $wpide_min_age ) )
    );
};

$wpide_age_check = function ( $errors ) use ( $wpide_min_age ) {
    if ( empty( $_POST['wpide_age_ok'] ) && is_wp_error( $errors ) ) {
        $errors->add( 'wpide_age', sprintf( '<strong>Error:</strong> You must be at least %d years old to register.', $wpide_min_age ) );
    }

    return $errors;
};

add_action( 'register_form', $wpide_age_field );
add_action( 'woocommerce_register_form', $wpide_age_field );
add_filter( 'registration_errors', $wpide_age_check, 20 );
add_filter( 'woocommerce_registration_errors', $wpide_age_check, 20 );
```

## Notes

Set $wpide_min_age to the age required in your country (13 to 16 under GDPR, 13 under COPPA).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require Age Confirmation When Registering" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
