Spin Wheel

⌘K
  1. Home
  2. Spin Wheel
  3. Hooks & Filters (Deve...
  4. After prize is selected (uspw_after_prize_selected)

After prize is selected (uspw_after_prize_selected)

The uspw_after_prize_selected Action Hook

uspw_after_prize_selected is an action that fires on the server the moment the winning slice has been drawn and its coupon code resolved, but before the JSON response is returned to the visitor’s browser. It is the ideal place to send real-time notifications, write to a custom log or table, or push conversion events to an external service. Available since version 1.0.0.

Important: this hook requires the Pro add-on

In Ultimate Spin Wheel, every uspw_* developer hook is wrapped in a Pro gate. The plugin only runs do_action( 'uspw_after_prize_selected', ... ) when apply_filters( 'ultimate_spin_wheel_pro_init', false ) returns true — which happens only when the separate Ultimate Spin Wheel Pro plugin is installed and active. On the free plugin alone this action never fires, so any callback you attach will simply not run until Pro is active.

Parameters

The action passes four arguments, so register it with an accepted-args count of 4:

  • $selected_prize (array): The winning slice’s stored data. Real keys are label, code, color, coupon_type, probability, is_unique, and (when set) image_url and message. There is no value, id, or image_id key — do not rely on those.
  • $campaign_id (int): The ID of the spin wheel campaign (a WordPress post ID).
  • $user_data (array): The submitted lead data, containing exactly email, name, and phone. Note that phone capture itself is a Pro feature, so phone is often an empty string.
  • $won_code (string): The actual coupon code assigned to this winner. For a Unique Pool slice this is the specific code that was just consumed; for a Lose (No Prize) slice it is typically empty.

Basic Usage

Attach a callback with add_action( 'uspw_after_prize_selected', 'my_prize_handler', 10, 4 ); and declare the four parameters in your function: function my_prize_handler( $selected_prize, $campaign_id, $user_data, $won_code ) { ... }. Inside, read the slice label with $selected_prize['label'] ?? '' and detect a losing spin by checking whether ( $selected_prize['coupon_type'] ?? 'static' ) === 'lose'.

Real-World Use Cases

Send real-time winner notifications

Alert your team the instant someone wins. In your callback, skip losing spins by returning early when coupon_type is lose, then post to a Slack incoming webhook with wp_remote_post() and/or send an email with wp_mail(). Build the message from $selected_prize['label'], $won_code, $user_data['email'], and $campaign_id. Because there is no numeric value field, target “high-value” prizes by matching the slice label or by keying off which $campaign_id fired.

Log wins to a custom table

Keep your own audit trail alongside the plugin’s built-in wp_wdengage_entries table. Use $wpdb->insert() to record $campaign_id, $selected_prize['label'], $selected_prize['probability'], $won_code, $user_data['email'], and current_time( 'mysql' ). This is handy for reconciling redemptions or for reporting on Unique Pool consumption over time.

Push conversion events to analytics or a CRM

Forward each win as a server-side event to a third-party endpoint with wp_remote_post() — for example a custom analytics API, a data warehouse, or a marketing platform. Send the slice label, the $won_code, the winner’s email, and the $campaign_id in a JSON body. Note that Ultimate Spin Wheel Pro already ships native integrations for Mailchimp, MailPoet, Klaviyo, ActiveCampaign, HubSpot, Zapier, and Pabbly, so reach for this hook only when you need a destination those integrations do not cover.

Notes & Gotchas

  • The hook fires before the response is sent, so heavy work (slow HTTP calls) will delay the visitor’s result. For anything non-trivial, offload to wp_schedule_single_event() or a background queue.
  • This action runs on the modern secure process_spin AJAX path. The winner is drawn on the server with wp_rand() before the wheel animates, so $selected_prize and $won_code are final and trustworthy at this point.
  • A losing spin only happens when a Lose (No Prize) slice (a Pro slice type) is configured and drawn. For those, coupon_type is lose and $won_code is empty — guard against empty codes accordingly.
  • Do not read $selected_prize['value'], ['id'], or ['image_id'] — those keys do not exist. Use label, coupon_type, probability, and image_url instead.

Related Documentation

Conclusion

The uspw_after_prize_selected action gives Pro developers a clean, server-side seam to react to every confirmed win — notifications, logging, and external integrations — with the final prize and coupon code in hand. Remember it only fires when Ultimate Spin Wheel Pro is active, keep your callbacks fast, and read only the fields that actually exist on $selected_prize. For help, visit the wowDevs support center.

How can we help?