wpgenie

masked usernames - pick number lottery

Feb 2nd, 2022 (edited)
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.50 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Lottery history tab template - masked usernames for Pick Number Mod addon
  4.  *
  5.  * This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/lottery-history.php
  6.  *
  7.  */
  8.  
  9. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  10.  
  11. global $woocommerce, $post, $product;
  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. ?>
  22.  
  23. <h2><?php echo esc_html( __( 'Lottery History', 'wc-lottery-pn' ) ); ?></h2>
  24.  
  25.  
  26. <?php if(($product->is_closed() === TRUE ) and ($product->is_started() === TRUE )) : ?>
  27.    
  28.     <p><?php _e('Lottery has finished', 'wc-lottery-pn') ?></p>
  29.     <?php if ($product->get_lottery_fail_reason() == '1'){
  30.          _e('Lottery failed because there were no minimal number of participants', 'wc-lottery-pn');
  31.     } else{
  32.  
  33.         if ( count($lottery_winers) > 1 ) { ?>
  34.  
  35.            <p><?php _e('Lottery winners are', 'wc-lottery-pn') ?>: <?php foreach ($lottery_winers as $winner_id) {
  36.             if( intval( $winner_id ) > 0) {
  37.  
  38.                     $dname = get_userdata($winner_id)->display_name;
  39.                     $length1      = strlen( $dname );
  40.                     $dname = $dname[0] . str_repeat( '*', $length1 - 2 ) . $dname[ $length1 - 1 ];
  41.  
  42.  
  43.                     $users_names .= "<span>";
  44.                     $users_names .= $dname;
  45.                     $users_names .= "</span>, ";
  46.                 }
  47.             } ?><?php echo rtrim( $users_names , ', '); ?></p>
  48.        
  49.         <?php } elseif( count($lottery_winers) === 1 ) {
  50.             $winner = reset($lottery_winers);
  51.  
  52.             if ( ! empty ( $winner ) ) { ?>
  53.             <p><?php _e('Lottery winner is:', 'wc-lottery-pn') ?> <span><?php echo get_userdata($winner)->display_name ?></span></p>
  54.         <?php }
  55.         }
  56.     } ?>
  57.                            
  58. <?php endif; ?>
  59.  
  60. <table>
  61.     <thead>
  62.         <tr>
  63.             <th><?php _e('Date', 'wc-lottery-pn') ?></th>
  64.             <th><?php _e('User', 'wc-lottery-pn') ?></th>
  65.             <?php if ($use_ticket_numbers === 'yes' ) :?>
  66.                 <th><?php _e('Ticket number', 'wc-lottery-pn') ?></th>
  67.             <?php endif; ?>
  68.             <?php if ($use_answers === true && 'yes' === get_option('lottery_answers_in_history', 'yes')  && ( 'no' === get_option('lottery_answers_in_history_finished', 'no') || $product->is_closed() === TRUE ) ) :?>
  69.                 <th><?php _e('Answer', 'wc-lottery-pn') ?></th>
  70.             <?php endif; ?>
  71.         </tr>
  72.     </thead>
  73.     <?php
  74.         $lottery_history = $product->lottery_history();
  75.        
  76.         if( $lottery_history ) {         
  77.        
  78.             foreach ($lottery_history as $history_value) {
  79.  
  80.                 if ($history_value->userid){
  81.                     $dname = get_userdata($history_value->userid)->display_name;
  82.                     $length1      = strlen( $dname );
  83.                     $dname = $dname[0] . str_repeat( '*', $length1 - 2 ) . $dname[ $length1 - 1 ];
  84.                 }
  85.  
  86.                 echo "<tr>";
  87.                 echo "<td class='date'>".date_i18n( $date_format, strtotime( $history_value->date )).' '.date_i18n( $time_format, strtotime( $history_value->date ))."</td>";
  88.                 echo $history_value->userid ? "<td class='username'>". $dname ."</td>" : '';
  89.  
  90.                 if ($use_ticket_numbers === 'yes' ) {
  91.                     echo "<td class='ticket_number'>" . apply_filters( 'ticket_number_display_html' , $history_value->ticket_number, $product ) . "</td>";
  92.                 }
  93.                
  94.                 if ( $use_answers === true && 'yes' === get_option('lottery_answers_in_history', 'yes')  && ( 'no' === get_option('lottery_answers_in_history_finished', 'no') || $product->is_closed() === TRUE ) ){
  95.                     $answer = isset( $answers[$history_value->answer_id] ) ? $answers[$history_value->answer_id] : false;
  96.                    
  97.                     echo "<td class='answer'>";
  98.                     echo $answer !== true ? $answer['text'] : "" ;
  99.                     echo "</td>";
  100.                 }
  101.                
  102.                 echo "</tr>";
  103.             }
  104.        
  105.         }
  106.     ?> 
  107.     <tr class="start">
  108.             <?php
  109.            
  110.             $lottery_dates_to = $product->get_lottery_dates_from();
  111.  
  112.  
  113.             if ($product->is_started() === TRUE ){
  114.                 echo '<td class="date">'.date_i18n( $date_format,  strtotime( $lottery_dates_to )).' '.date_i18n( $time_format,  strtotime( $lottery_dates_to )).'</td>';              
  115.                 echo '<td class="started">';
  116.                 esc_html_e( 'Lottery started', 'wc-lottery-pn' );
  117.                 echo '</td>';
  118.  
  119.             } else {
  120.                 echo '<td class="date">'.date_i18n( $date_format,  strtotime( $lottery_dates_to )).' '.date_i18n( $time_format,  strtotime( $lottery_dates_to )).'</td>';              
  121.                 echo '<td class="starting">';
  122.                 esc_html_e( 'Lottery starting', 'wc-lottery-pn' );
  123.                 echo '</td>' ;
  124.             }?>
  125.     </tr>
  126. </table>
Add Comment
Please, Sign In to add comment