wpgenie

masked usernames - lottery

Feb 2nd, 2022 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Lottery history tab template - masked usernames
  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. $heading = esc_html(  __( 'Lottery history', 'wc_lottery' )  );
  14. $lottery_winers = get_post_meta($post->ID, '_lottery_winners');
  15. $users_names = '';
  16.  
  17. ?>
  18.  
  19. <h2><?php echo $heading; ?></h2>
  20.  
  21.  
  22. <?php if(($product->is_closed() === TRUE ) and ($product->is_started() === TRUE )) : ?>
  23.    
  24.     <p><?php _e('Lottery has finished', 'wc_lottery') ?></p>
  25.     <?php if ($product->get_lottery_fail_reason() == '1'){
  26.          _e('Lottery failed because there were no minimum users', 'wc_lottery');
  27.     } else{
  28.  
  29.        
  30.         if (count($lottery_winers) > 1) { ?>
  31.            <p><?php _e('Lottery winners are', 'wc_lottery') ?>: <?php foreach ($lottery_winers as $winner_id) {
  32.             if( intval( $winner_id ) > 0) {
  33.  
  34.                 $dname = get_userdata($winner_id)->display_name;
  35.                 $length1      = strlen( $dname );
  36.                 $dname = $dname[0] . str_repeat( '*', $length1 - 2 ) . $dname[ $length1 - 1 ];
  37.  
  38.                     $users_names .= "<span>";
  39.                     $users_names .= $dname;
  40.                     $users_names .= "</span>, ";
  41.                 }
  42.             } ?><?php echo rtrim( $users_names , ', '); ?></p>
  43.         <?php } elseif(count($lottery_winers) == 1) { ?>
  44.             <p><?php _e('Lottery winner is', 'wc_lottery') ?>: <span><?php echo get_userdata($lottery_winers[0])->display_name ?></span></p>
  45.         <?php }
  46.     } ?>
  47.                            
  48. <?php endif; ?>
  49.  
  50. <table>
  51.     <thead>
  52.         <tr>
  53.             <th><?php _e('Date', 'wc_lottery') ?></th>
  54.             <th><?php _e('User', 'wc_lottery') ?></th>
  55.         </tr>
  56.     </thead>
  57.     <?php
  58.         $lottery_history = $product->lottery_history();
  59.        
  60.         if( $lottery_history ) {
  61.        
  62.             foreach ($lottery_history as $history_value) {
  63.                 echo "<tr>";
  64.                 echo "<td class='date'>".date_i18n( get_option( 'date_format' ), strtotime( $history_value->date )).' '.date_i18n( get_option( 'time_format' ), strtotime( $history_value->date ))."</td>";
  65.                
  66.                 $dname = get_userdata($history_value->userid)->display_name;
  67.                 $length1      = strlen( $dname );
  68.                 $dname = $dname[0] . str_repeat( '*', $length1 - 2 ) . $dname[ $length1 - 1 ];
  69.  
  70.                 echo $history_value->userid ? "<td class='username'>".$dname."</td>" : '';
  71.                 echo "</tr>";
  72.             }        
  73.         }
  74.     ?>    
  75.     <tr class="start">            
  76.     <?php
  77.         $lottery_dates_to = $product->get_lottery_dates_from();
  78.         if ($product->is_started() === TRUE ){                
  79.             echo '<td class="date">'.date_i18n( get_option( 'date_format' ), strtotime( $lottery_dates_to )).' '.date_i18n( get_option( 'time_format' ),  strtotime( $lottery_dates_to )).'</td>';            
  80.             echo '<td class="started">';
  81.             echo apply_filters('lottery_history_started_text', __( 'Lottery started', 'wc_lottery' ), $product);
  82.             echo '</td>';
  83.         } else {
  84.             echo '<td class="date">'.date_i18n( get_option( 'date_format' ), strtotime( $lottery_dates_to )).' '.date_i18n( get_option( 'time_format' ),  strtotime( $lottery_dates_to )).'</td>';                
  85.             echo '<td  class="starting">';
  86.             echo apply_filters('lottery_history_starting_text', __( 'Lottery starting', 'wc_lottery' ), $product);
  87.             echo '</td>' ;
  88.         }?>
  89.     </tr>
  90. </table>
Add Comment
Please, Sign In to add comment