/** * Add Custom Lottery Prize * @since 1.0 */ add_filter( 'mycred_lotto_winners_get', 'mycred_pro_add_custom_lottery_prize' ); function mycred_pro_add_custom_lottery_prize( $prizes ) { $prizes['ingame'] = 'In-game item'; return $prizes; } /** * Add Custom Lottery Prize Settings * @since 1.0 */ add_action( 'mycred_lotto_winnings_ingame', 'mycred_pro_add_custom_lottery_prize_settings', 10, 2 ); function mycred_pro_add_custom_lottery_prize_settings( $i, $lottery ) { $winnings = $lottery->get_winnings_prefs(); if ( isset( $winnings['draw'][ $i ] ) ) $value = $winnings['draw'][ $i ]; else $value = ''; echo ''; } /** * Handle Custom Lottery Prize Win * @version 1.0 */ add_action( 'mycred_lotto_give_ingame', 'mycred_pro_custom_lottery_prize_payout', 10, 3 ); function mycred_pro_custom_lottery_prize_payout( $product_winners, $winning_user_ids, $lottery ) { // Get the "Winnings" settings for this lottery $winnings = $lottery->get_winnings_prefs(); // Get the "Templates" settings for this ltotery $templates = $lottery->get_templates_prefs(); $admin_email = ''; // Lets loop through our winners foreach ( $winning_user_ids as $pick => $user_id ) { // IF you do not want a drawn winner to get anything make sure the field is empty if ( $winnings['draw'][ $pick ] == '' ) continue; // The prize should be saved in the draw field $prize = sanitize_text_field( $winnings['draw'][ $pick ] ); // Make sure the winning user still exists $winning_user = get_userdata( absint( $user_id ) ); if ( isset( $winning_user->ID ) ) { // Replace %prize% template tag with the actual prize $template = str_replace( '%prize%', $prize, $templates['win'] ); // Send Email wp_mail( $winning_user->user_email, 'Lottery Win!', $template ); $admin_email .= sprintf( 'User: %s won: %s', $winning_user->display_name, $prize ) . "\n"; } } // Finally, lets send an email to the admin to let him know that winners have been drawn $message = sprintf( 'The following users has been selected winners: %s.', $admin_email ); wp_mail( get_option( 'admin_email' ), 'In-Game Lottery Win!', $message ); }