Advertisement
wpgenie

auctions show counter in the loop

Mar 13th, 2018 (edited)
6,840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /* visit us - https://wpgenie.org */
  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.     global $product;
  7.  
  8.     $time = '';
  9.  
  10.     if ( ! isset( $product ) ) {
  11.         return;
  12.     }
  13.     if ( 'auction' !== $product->get_type() ) {
  14.         return;
  15.     }
  16.  
  17.     $timetext = esc_html__( 'Time left', 'wc_simple_auctions' );
  18.  
  19.     if ( ! $product->is_started() ) {
  20.         $timetext     = esc_html__( 'Starting in', 'wc_simple_auctions' );
  21.         $counter_time = $product->get_seconds_to_auction();
  22.     } else {
  23.         $counter_time = $product->get_seconds_remaining();
  24.     }
  25.     $future_class = ( $product->is_closed() === false ) && ( $product->is_started() === false ) ? 'future' : '';
  26.  
  27.     $time = '<span class="time-left ">' . $timetext . '</span>
  28.     <div class="auction-time-countdown ' . $future_class . '"
  29.     data-time="' . esc_attr( $counter_time ) . '"
  30.     data-auctionid="' . intval( $product->get_id() ) . '" data-format="' . esc_attr( get_option( 'simple_auctions_countdown_format' ) ) . '"></div>';
  31.  
  32.     if ( $product->is_closed() ) {
  33.         $time = '<span class="has-finished">' . __( 'Auction finished', 'wc_simple_auctions' ) . '</span>';
  34.     }
  35.  
  36.     echo $time;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement