Developer Hooks
Run your own code after a successful AgeOnce verification
Developer Hooks
Plugin version 1.0.9 fires a WordPress action after AgeOnce confirms a successful verification. Use it to assign a custom role or record your own audit metadata. The plugin does not assign membership roles or unlock paid content.
The action runs on the OAuth callback, before the customer places or pays for an order. user_id is 0 when the visitor is not logged in.
ageonce_verification_completed
add_action( 'ageonce_verification_completed', function ( $verification ) {
$user_id = isset( $verification['user_id'] ) ? (int) $verification['user_id'] : 0;
if ( $user_id <= 0 ) {
return;
}
// $verification['transaction_id'], ['min_age'], ['context'], ['verified_at']
}, 10, 1 );| Key | Type | Meaning |
|---|---|---|
user_id | int | WordPress user ID. 0 if the visitor is not logged in. |
transaction_id | string | AgeOnce audit ID. Empty string if the API did not return one. |
min_age | int | Age threshold requested for this check (for example 18). |
context | string | checkout, content, or signup. |
verified_at | int | Unix timestamp (UTC) of this success. |
Stored on the WordPress user
When user_id is greater than 0, the plugin also writes user meta:
| Meta key | Value |
|---|---|
_ageonce_status | verified |
_ageonce_required_age | Highest age threshold passed on this account |
_ageonce_transaction_id | Latest transaction ID |
_ageonce_timestamp | Latest verification time in the site timezone |
_ageonce_age_passes | Array of age => [ 'ts' => unix time, 'tx' => transaction ID ]. The pass duration is measured from these times. |
_ageonce_reset_at | Unix time of the last administrator reset. Device passes created before it no longer count. |
A later checkout, signup, or content gate for the same age (or a lower one) accepts this stored result until the pass duration for that surface has passed. An 18+ result does not satisfy a 21+ rule. Logging out clears the session, the cookies, and the account's pass times (_ageonce_timestamp and _ageonce_age_passes). The status and highest verified age stay on the account.
Guests are not stored on a user. Their result stays in the WooCommerce session and a cookie for 24 hours at most. Without WooCommerce, only the cookie is set.
The same user meta is written when WooCommerce customer signup creates a new store account after verification. Signup verification is off by default.
// Third argument: 'content' (default) or 'checkout'. It picks the duration set in the plugin settings.
AgeOnce_API::is_user_verification_valid( $user_id, 18, 'checkout' );
AgeOnce_API::is_verified( true, 18, 'content' );Reset a user's verification
Administrators can reset a customer from the WordPress user profile. In code:
AgeOnce_API::reset_user_verification( $user_id );This deletes the stored status, age, time, transaction ID, and per-age records, and marks the reset time so passes on the person's devices stop counting. It fires an action you can use to keep your own records in step:
add_action( 'ageonce_user_verification_reset', function ( $user_id ) {
// Remove a custom role or flag you added after verification.
}, 10, 1 );Role after a paid verification product
If the "18+" marker should exist only after the verification product is paid, do not grant it inside ageonce_verification_completed. Grant it when WooCommerce completes that order. The current plugin already saves _ageonce_status and _ageonce_transaction_id on the order.
Create the role once (Users → the role slug should not be 18+; WordPress strips + from slugs). Display name can still be 18+. Slug example: verified_18.
add_action( 'woocommerce_order_status_completed', 'ageonce_grant_verified_role' );
add_action( 'woocommerce_order_status_processing', 'ageonce_grant_verified_role' );
function ageonce_grant_verified_role( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || 'verified' !== $order->get_meta( '_ageonce_status' ) ) {
return;
}
$verification_product_id = 123; // Age verification product ID.
$matches = false;
foreach ( $order->get_items() as $item ) {
if ( (int) $item->get_product_id() === $verification_product_id ) {
$matches = true;
break;
}
}
if ( ! $matches ) {
return;
}
$user = get_userdata( $order->get_user_id() );
if ( $user ) {
$user->add_role( 'verified_18' );
}
}add_role() keeps the existing customer role. Configure Ultimate Member so a later Guest or Fanbase role is added the same way, if the member still needs verified_18.
Show membership products only to verified users
Restrict purchase and catalog visibility in WooCommerce. This is store logic, not AgeOnce.
add_filter( 'woocommerce_is_purchasable', 'ageonce_limit_membership_products', 10, 2 );
add_filter( 'woocommerce_product_is_visible', 'ageonce_limit_membership_products', 10, 2 );
function ageonce_limit_membership_products( $allowed, $product ) {
$membership_ids = array( 456, 789 ); // Guest and Fanbase product IDs.
$product_id = $product instanceof WC_Product ? $product->get_id() : (int) $product;
if ( ! in_array( $product_id, $membership_ids, true ) ) {
return $allowed;
}
$user = wp_get_current_user();
if ( ! $user || ! in_array( 'verified_18', (array) $user->roles, true ) ) {
return false;
}
return $allowed;
}Place both snippets in a small custom plugin or a child theme functions.php. Do not edit the AgeOnce plugin.