Note: this tutorial is meant for the premium version.

You may want to be alerted when someone spun a wheel and won a prize. To keep the plugin fast and lightweight, we purposefully did not build this as a setting in WP Optin Wheel. However, you can easily enable this feature by pasting some code into your theme’s functions.php file.

Below is the code. We’ve put comments where you need to make changes.

// This action is fired each time someone played the wheel.
add_action('wof_play','wof_send_email_when_won');

function wof_send_email_when_won($data) {

	// Only if the player won.
	if($data['winning'] === true) {
	
		// Start building the email message
		$message = "Someone won a prize. Here is some useful data: <br/>";
		$message .= "Wheel ID: ".$data['wheel']."<br/>";
		if(!empty($data['email']))
			$message .= "Email address: ".$data['email']."<br/>";
		$message .= "Landed on this segment: '".$data['segment_text']."'<br/>";
		$message .= "The value of the prize: ".$data['segment_prize']."<br/>";
		$message .= "This happened on: ".$data['timestamp']."<br/><br/>";
		$message .= "This is an automated message. Do not reply.";
		
		// Set the content type of the email to HTML.
		add_filter( 'wp_mail_content_type', 'wof_set_email_content_type');
		
		// Send the email
		wp_mail(
			"[email protected]", // CHANGE THIS to the address you'd like to send the email to.
			"Someone won a prize!", // The subject of the mail.
			$message
		);
		
		// Set content type back to default.
		remove_filter( 'wp_mail_content_type','wof_set_email_content_type');
	}
}

// Set the content type of the email to HTML.
function wof_set_email_content_type(){
	return "text/html";
}