Skip to main content

Referral Program

Goal​

Give each customer a referral code, attribute signups and orders back to whoever sent them, and record a reward for the referrer. It is for shops that want customers recruiting customers, with a leaderboard and optional tiers.

Tier and entitlement​

FieldValue
TierPremium
Entitlement keyreferral-program
Admin tabreferrals
Module keyreferral-program
Settings prefixaiowc_ref_

Hooks register only when aiowc_module_enabled_referral-program is true and the licence permits the referral-program entitlement.

How attribution works​

  1. A visitor arrives with ?ref=CODE. On init at priority 5 the click is recorded and the code is written to the aiowc_ref cookie for cookie_duration days.
  2. On user_register, a signup is recorded against the cookie's code. Self-referral is refused unless allow_self_referral is on.
  3. On woocommerce_checkout_order_processed, the code is resolved to a referrer and a referral row is created for the order. An existing pending referral for the same order and referrer is not duplicated.
  4. On woocommerce_order_status_completed, the referral becomes eligible for a reward.
  5. The daily rewards job issues rewards for eligible referrals, subject to min_order_total and require_approval.

Rewards — how a payout is delivered​

Service/RewardService.php writes a reward row, attempts delivery, and moves the reward to issued and the referral to paid only when a listener confirms the reward actually landed. Each reward type fires an action for third-party listeners, then reads a filter that reports whether delivery succeeded:

reward_typeAction firedDelivery filterAnswered by
store_creditaiowc_award_store_creditaiowc_referral_store_credit_deliveredThe Wallet module, when enabled
couponaiowc_create_coupon_for_useraiowc_referral_coupon_deliveredThe Referral Program module itself
cashNo action is fired—Nothing — see below

A store_credit reward is credited to the customer's wallet, so it needs the Wallet module enabled. With Wallet switched off nothing answers the filter, delivery is not confirmed, and the reward stays pending rather than being marked paid. A site can supply its own listener for either filter.

cash is deliberately absent: there is no automated payout, so the reward stays pending and the referral stays where it was until a human records the payment.

redeemReward() only moves a reward row from issued to redeemed.

Settings​

Read through ModuleSettings with the aiowc_ref_ prefix; defaults are ReferralProgramModule::DEFAULTS. All ten are consulted.

SettingDefaultMeaning
enable_referralstrueMaster switch
commission_typepercentageHow commission_rate is read
commission_rate10.0Reward size, as a percentage or a fixed amount
reward_typestore_creditOne of store_credit, coupon or cash
min_order_total0.0Order value a referral must reach to earn a reward
cookie_duration30Days the aiowc_ref cookie survives
require_approvalfalseWhether a referral must be approved before a reward is issued
allow_self_referralfalseWhether a user may redeem their own code
enable_tierstrueWhether the tier system applies
show_leaderboardtrueWhether the public leaderboard is offered

Admin screen​

Admin tab referrals. It lists referrals by status, shows the programme statistics, and carries the settings form.

Database schema​

Created by Schema/ReferralsSchema.php at schema version 1.0.0.

TableHolds
{prefix}aiowc_referral_codesOne code per participating user
{prefix}aiowc_referralsAttributed signups and orders, with status
{prefix}aiowc_referral_rewardsReward rows, with reward_type defaulting to store_credit and a status of issued or redeemed
{prefix}aiowc_referral_tiersTier definitions; a user's current tier is held in the _aiowc_referral_tier_id user meta

REST endpoints​

Namespace aiowc/v1. All responses use the shared envelope.

Participant​

MethodPathPurposeRequired argsPermission
GET/referrals/my-codeThe signed-in user's referral code—Signed in
GET/referrals/statsThe signed-in user's own figures—Signed in
GET/referrals/rewardsThe signed-in user's rewards—Signed in
POST/referrals/redeemRedeem one rewardreward_idSigned in

Public​

MethodPathPurposeRequired argsPermission
GET/referrals/leaderboardTop referrers, up to limit—Rate-limited public read
POST/referrals/track-clickRecord a click on a codecodePublic write check

Shop​

Permission: manage.

MethodPathPurposeRequired args
GET/referrals/admin/referralsList referrals, filterable by status, paginated—
GET/referrals/admin/statsProgramme statistics—
GET/referrals/settingsRead settings—
PUT / PATCH / POST/referrals/settingsUpdate settings—

WooCommerce and WordPress integration​

HookPriorityEffect
init5Reads ?ref= from the request, records the click and sets the aiowc_ref cookie
user_register10Attributes a signup to the cookie's code
woocommerce_checkout_order_processed10Creates the referral row for the order
woocommerce_order_status_completed10Makes the referral eligible for a reward

Shortcode​

ShortcodePurpose
[aiowc_referral_dashboard]The participant's own code, statistics and rewards

No block is registered.

Emitted actions​

ActionFired when
aiowc_award_store_creditA store_credit reward is issued — no listener ships
aiowc_create_coupon_for_userA coupon reward is issued — no listener ships
aiowc_track_event with referral_reward_issuedA reward row is written
aiowc_track_event with referral_reward_redeemedA reward is redeemed

Background jobs​

All three run on the WordPress cron scheduler, daily.

HookPurpose
aiowc_referral_process_rewardsIssues rewards for eligible referrals
aiowc_referral_tier_updatesRecalculates each participant's tier and writes _aiowc_referral_tier_id
aiowc_referral_cleanupPrunes referral data past the retention window

Entitlement limits​

The referral-program entitlement gates the module as a whole. min_order_total and commission_rate are programme settings, not licence limits, and no cap on codes, referrals or rewards is implemented.