AgeOnce Docs
WordPress

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 );
KeyTypeMeaning
user_idintWordPress user ID. 0 if the visitor is not logged in.
transaction_idstringAgeOnce audit ID. Empty string if the API did not return one.
min_ageintAge threshold requested for this check (for example 18).
contextstringcheckout, content, or signup.
verified_atintUnix timestamp (UTC) of this success.

Stored on the WordPress user

When user_id is greater than 0, the plugin also writes user meta:

Meta keyValue
_ageonce_statusverified
_ageonce_required_ageHighest age threshold passed on this account
_ageonce_transaction_idLatest transaction ID
_ageonce_timestampVerification time in the site timezone

A later checkout, signup, or content gate for the same age (or a lower one) accepts this stored result. An 18+ result does not satisfy a 21+ rule. Logging out clears the session and cookie, not this account record.

Guests are not stored on a user. Their result stays in the WooCommerce session and a cookie for 24 hours. 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.

AgeOnce_API::is_user_verification_valid( $user_id, 18 );
AgeOnce_API::is_verified( true, 18 );

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.

On this page