wpgenie

Adding lottery info to the loop

Jun 25th, 2020
1,860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. add_action( 'woocommerce_after_shop_loop_item_title' , 'lottery_custom_info',80 );
  2. function lottery_custom_info(){
  3.     global $product;
  4.     if ( ! is_object( $product)) $product = wc_get_product( get_the_ID() );
  5.     if ( $product && $product->get_type() == 'lottery' ) {
  6.         $max_tickets                = $product->get_max_tickets();
  7.         $lottery_participants_count = !empty($product->get_lottery_participants_count()) ? $product->get_lottery_participants_count() : '0';
  8.         ?>
  9.         <span class="lottery-timer">
  10.             <i class="fas fa-clock"></i><div class="lottery-time-countdown-compact" data-time="<?php echo $product->get_seconds_remaining() ?>" data-lotteryid="<?php echo $product->get_id() ?>" data-format="<?php echo get_option( 'simple_lottery_countdown_format' ) ?>"></div>
  11.         </span>
  12.       <span class="remaining-tickets">
  13.         <i class="fas fa-ticket-alt"></i><?php echo ($max_tickets - $lottery_participants_count); ?> <?php _e( 'Remaining', 'wc_lottery_custom' )?>
  14.       </span>
  15.       <span class="max-pp-tickets">
  16.         <i class="fas fa-user"></i><?php _e( 'max', 'wc_lottery_custom' )?> <?php echo ($product->get_max_tickets_per_user()); ?> <?php _e( 'pp', 'wc_lottery_custom' )?>
  17.       </span>
  18.     <?php }
  19.  
  20. }
  21. add_action('wp_footer', 'custom_footer_script');
  22. function custom_footer_script(){ ?>
  23. <script>
  24. jQuery(document).ready(function($){
  25.  
  26.     $(".lottery-time-countdown-compact").each(function(index) {
  27.  
  28.         var time = $(this).data('time');
  29.         var format = $(this).data('format');
  30.         if (format == '') {
  31.             format = 'yowdHMS';
  32.         }
  33.  
  34.         $(this).wc_lotery_countdown({
  35.             until: $.wc_lotery_countdown.UTCDate(-(new Date().getTimezoneOffset()), new Date(time * 1000)),
  36.             // format: format,
  37.             compact: true,
  38.             significant: 1,
  39.             layout: '{d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}'
  40.         });
  41.  
  42.     });
  43. })
  44. </script>
  45. <?php }
Advertisement
Add Comment
Please, Sign In to add comment