wpgenie

show lottery counter / countdown in loop / archive

May 3rd, 2017 (edited)
1,041
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* available as plugin https://wpgenie.org/woocommerce-lottery/documentation/assets/woocommerce-lottery-progress-bar-in-loop.zip */
  2.  
  3.         add_action( 'woocommerce_after_shop_loop_item_title','wpgenie_show_counter_in_loop',50 );
  4.  
  5.         function wpgenie_show_counter_in_loop(){
  6.  
  7.             global $product;
  8.  
  9.             $time = '';
  10.  
  11.             if(!isset ($product))
  12.                 return;
  13.             if('lottery' != $product->get_type())
  14.                 return;
  15.  
  16.             $timetext = __('Time left', 'wc_lottery');
  17.  
  18.             if(!$product->is_started()){
  19.                 $timetext = __('Starting in', 'wc_lottery');
  20.                 $counter_time = $product->get_seconds_to_lottery();
  21.             } else{
  22.                 $counter_time = $product->get_seconds_remaining();
  23.             }
  24.  
  25.             $time = '<span class="time-left">'.$timetext.'</span>
  26.             <div class="lottery-time-countdown"
  27.             data-time="'.$counter_time.'"
  28.             data-lotteryid="'.$product->get_id().'" data-format="'.get_option(
  29.             'simple_lottery_countdown_format' ).'"></div>';
  30.  
  31.             if($product->is_closed()){
  32.                 $time = '<span class="has-finished">'.__('Lottery finished','wc_lottery').'</span>';
  33.             }
  34.             echo $time;
  35.         }
RAW Paste Data Copied