Advertisement
wpgenie

show real names for instant winners tab

Mar 13th, 2023
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Lottery instant winners tab template
  4.  *
  5.  * This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/lottery-instant-winners.php
  6.  *
  7.  */
  8.  
  9. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  10.  
  11. global $post;
  12.  
  13. $lottery_winers = get_post_meta($post->ID, '_lottery_winners');
  14. $users_names = '';
  15. $use_answers = wc_lottery_use_answers( $post->ID );
  16. $use_ticket_numbers = get_post_meta( $post->ID , '_lottery_use_pick_numbers', true );
  17. $answers = maybe_unserialize( get_post_meta( $post->ID, '_lottery_pn_answers', true ) );
  18. $date_format = get_option( 'date_format' );
  19. $time_format = get_option( 'time_format' );
  20.  
  21. $prizes = wc_lottery_get_lottery_instant_ticket_numbers_prizes_field( $post->ID  );
  22. $lottery_instant_instant_winners = get_post_meta( $post->ID, '_lottery_instant_instant_winners');
  23. $lottery_pick_numbers_random = get_post_meta( $post->ID , '_lottery_pick_numbers_random', true );
  24.  
  25.  
  26. if ( empty( $prizes ) ){
  27.         return;
  28. }
  29. ?>
  30.  
  31. <h2><?php echo esc_html( __( 'Instant prizes and winners', 'wc-lottery-pn' ) ); ?></h2>
  32.  
  33. <table>
  34.     <thead>
  35.         <tr>
  36.             <th><?php _e('Ticket', 'wc-lottery-pn') ?></th>
  37.             <th><?php _e('Prize', 'wc-lottery-pn') ?></th>
  38.             <th><?php _e('Winner', 'wc-lottery-pn') ?></th>
  39.         </tr>
  40.     </thead>
  41.  
  42.         <?php
  43.  
  44.         foreach ($prizes as $prize) {
  45.             $winner_found = false;
  46.             $display_name = '';
  47.             if ( $lottery_instant_instant_winners ){
  48.                 foreach ($lottery_instant_instant_winners as $winner) {
  49.                     if ( $winner['ticket'] == $prize['ticket'] ){
  50.                         $winner_found = true;
  51.                         $user_data = get_userdata( $winner['user_id'] );
  52.                         $display_name = $user_data ? $user_data->first_name.' '.$user_data->last_name : '';
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.  
  58.             if( $lottery_pick_numbers_random !== 'yes' && $winner_found === false ){
  59.                 $prize['ticket'] = '';
  60.             }
  61.             echo '<tr>';
  62.                     echo '<td class="ticket">'. ($prize['ticket'] ? $prize['ticket'] : '-') . '</td>';
  63.                     echo '<td class="prize">'. $prize['prize'] . '</td>';
  64.                     echo '<td class="winner">' . ($display_name ? $display_name : '-') . '</td>';
  65.  
  66.                 echo '</tr>';
  67.             }
  68.  
  69.  
  70.         ?>
  71.  
  72. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement