Return whether the current visitor is assigned to a specific experiment variant. Use this in themes or plugins to branch markup, enqueue assets, or add filters for one arm of an A/B test.
Reads the assignment Alpha Insights already applied on the current request (after the wp hook). Returns true only when the visitor is in that experiment slug and variant key. Holdout visitors, unassigned visitors, and requests where the experiment is not applied return false.
File: includes/experiments/wpd-experiment-functions.php
Line: ~37
wpdai_in_experiment( string $experiment_slug, string $variant_key ): bool
| Parameter | Type | Required | Description |
|---|---|---|---|
| $experiment_slug | string | Yes | A/B test slug from A/B Test → Edit (not the display name). |
| $variant_key | string | Yes | Variant key, typically control or treatment. Must match the key stored on the variant. |
Type: bool
Description: true if the current visitor’s assigned variant equals $variant_key for that slug; otherwise false.
if ( function_exists( 'wpdai_in_experiment' ) && wpdai_in_experiment( 'pricing-headline', 'treatment' ) ) {
echo 'New headline';
} else {
echo 'Original headline';
}
add_action( 'wp', function() {
if ( function_exists( 'wpdai_in_experiment' ) && wpdai_in_experiment( 'cart-upsell', 'treatment' ) ) {
add_action( 'woocommerce_after_cart_table', 'my_treatment_upsell' );
}
} );
wp. Assignment has not run yet on earlier hooks such as plugins_loaded.function_exists() so the theme stays safe if A/B Testing is not loaded.