Advertisement
wpgenie

shortcode recent bids

Jun 29th, 2019
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. add_action( 'wp', 'custom_add_shortcodes' );
  2.  
  3. function custom_add_shortcodes() {
  4.     add_shortcode( 'custom_auctions_recent_bids', 'custom_auctions_recent_bids' );
  5. }
  6.  
  7. function custom_auctions_recent_bids( $atts ) {
  8.     global $wpdb;
  9.  
  10.     extract(
  11.         shortcode_atts(
  12.             array(
  13.                 'limit'          => 20,
  14.                 'show_usernames' => 'yes',
  15.  
  16.             ),
  17.             $atts
  18.         )
  19.     );
  20.     $user_id          = get_current_user_id();
  21.     $auction_activity = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'simple_auction_log ORDER BY date DESC limit %d ', $limit ) );
  22.  
  23.     if ( $auction_activity ) {
  24.         echo '<table class="auctions_activity">';
  25.         echo '<tr>';
  26.         echo '<th>' . esc_html__( 'Date', 'wc_simple_auctions' ) . '</th>';
  27.         echo '<th>' . esc_html__( 'Auction', 'wc_simple_auctions' ) . '</th>';
  28.         if ( 'yes' === $show_usernames ) {
  29.             echo '<th>' . esc_html__( 'Username', 'wc_simple_auctions' ) . '</th>';
  30.         }
  31.         echo '<th>' . esc_html__( 'Bid', 'wc_simple_auctions' ) . '</th>';
  32.         echo '<th>' . esc_html__( 'Status', 'wc_simple_auctions' ) . '</th>';
  33.         echo '</tr>';
  34.  
  35.         foreach ( $auction_activity as $key => $value ) {
  36.             if ( get_post_status( $value->auction_id ) === 'publish' ) {
  37.                 $class   = '';
  38.                 $product = wc_get_product( $value->auction_id );
  39.  
  40.                 if ( $product && $product->is_type( 'auction' ) ) {
  41.                     if ( $product->is_closed() ) {
  42.                         $class .= 'closed ';
  43.                     }
  44.  
  45.                     if ( $product->get_auction_current_bider() === $user_id && ! $product->is_sealed() ) {
  46.                         $class .= 'winning ';
  47.                     }
  48.  
  49.                     if ( $product->get_auction_current_bider() === $user_id && ! $product->is_reserve_met() ) {
  50.                         $class .= 'reserved ';
  51.                     }
  52.  
  53.                     if ( strtotime( $product->get_auction_relisted() ) > strtotime( $value->date ) ) {
  54.                         $class .= 'relisted ';
  55.                     }
  56.  
  57.                     echo '<tr class="' . esc_attr( $class ) . '">';
  58.                     echo '<td>' . esc_html( date_i18n( get_option( 'date_format' ), strtotime( $value->date ) ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $value->date ) ) ) . '</td>';
  59.                     echo '<td><a href="' . esc_url( get_permalink( $value->auction_id ) ) . '">' . esc_html( get_the_title( $value->auction_id ) ) . '</a></td>';
  60.                     if ( 'yes' === $show_usernames ) {
  61.                         echo '<td>';
  62.                         $userdata = get_userdata( $value->userid );
  63.                         if ( $userdata ) {
  64.                             echo esc_attr( $userdata->user_nicename );
  65.                         } else {
  66.                             esc_html_e( 'n/a', 'wc_simple_auctions' );
  67.                         }
  68.                         echo '</td>';
  69.                     }
  70.                     echo '<td>' . wc_price( $value->bid ) . '</td>';
  71.                     echo '<td>' . $product->get_price_html() . '</td>';
  72.                     echo '</tr>';
  73.                 }
  74.             }
  75.         }
  76.         echo '</table>';
  77.     } else {
  78.         echo '<div class="woocommerce"><p class="woocommerce-info">' . esc_html__( 'There is not any bids at the moment!.', 'wc_simple_auctions' ) . '</p></div>';
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement