# Age Confirmation Checkbox at Checkout

> Adds a required "I confirm I am 18 or older" checkbox to the classic checkout and records the confirmation on the order.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, age, compliance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-age-confirmation-checkbox/

## Code

```php
$wpide_min_age = 18; // Minimum age the customer must confirm.

add_action( 'woocommerce_review_order_before_submit', function () use ( $wpide_min_age ) {
    woocommerce_form_field( 'wpide_age_confirm', array(
        'type'     => 'checkbox',
        'class'    => array( 'form-row', 'validate-required' ),
        'label'    => sprintf( 'I confirm that I am %d years or older.', $wpide_min_age ),
        'required' => true,
    ) );
} );

add_action( 'woocommerce_checkout_process', function () {
    if ( empty( $_POST['wpide_age_confirm'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
        wc_add_notice( 'Please confirm your age to place the order.', 'error' );
    }
} );

add_action( 'woocommerce_checkout_create_order', function ( $order ) use ( $wpide_min_age ) {
    if ( ! empty( $_POST['wpide_age_confirm'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
        $order->update_meta_data( '_wpide_age_confirmed', $wpide_min_age . '+ confirmed ' . current_time( 'mysql' ) );
    }
} );
```

## Notes

Change $age to your legal age. This is a self-declaration, not an identity check.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Age Confirmation Checkbox at Checkout" 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/
