wpgenie

Auction bid with check that prevents authors / sellers to bid on their own auctions.

Aug 3rd, 2020 (edited)
1,915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Auction bid with check that prevents authors / sellers to bid on their own auctions. This is modified bid.php template.
  4.  *
  5.  * Should go to your_child_theme\woocommerce\single-product\bid.php folder.
  6.  */
  7.  
  8. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  9.  
  10. global $woocommerce, $product, $post;
  11.  
  12. if(!(method_exists( $product, 'get_type') && $product->get_type() == 'auction')){
  13.     return;
  14. }
  15.  
  16. $current_user = wp_get_current_user();
  17. $product_id =  $product->get_id();
  18. $user_max_bid = $product->get_user_max_bid($product_id ,$current_user->ID );
  19. $max_min_bid_text = $product->get_auction_type() == 'reverse' ? __( 'Your min bid is', 'wc_simple_auctions' ) : __( 'Your max bid is', 'wc_simple_auctions' );
  20. $gmt_offset = get_option('gmt_offset') > 0 ? '+'.get_option('gmt_offset') : get_option('gmt_offset');
  21. $dateformat = get_option( 'date_format' );
  22. $timeformat = get_option( 'time_format' );
  23. ?>
  24.    
  25. <p class="auction-condition"><?php echo apply_filters('conditiond_text', __( 'Item condition:', 'wc_simple_auctions' ), $product); ?><span class="curent-bid"> <?php  _e($product->get_condition(),'wc_simple_auctions' )  ?></span></p>
  26.  
  27. <?php if(($product->is_closed() === FALSE ) and ($product->is_started() === TRUE )) : ?>           
  28.        
  29.     <div class="auction-time" id="countdown"><?php echo apply_filters('time_text', __( 'Time left:', 'wc_simple_auctions' ), $product_id); ?>
  30.         <div class="main-auction auction-time-countdown" data-time="<?php echo $product->get_seconds_remaining() ?>" data-auctionid="<?php echo $product_id ?>" data-format="<?php echo get_option( 'simple_auctions_countdown_format' ) ?>"></div>
  31.     </div>
  32.  
  33.     <div class='auction-ajax-change' >
  34.        
  35.         <p class="auction-end"><?php echo apply_filters('time_left_text', __( 'Auction ends:', 'wc_simple_auctions' ), $product); ?> <?php echo  date_i18n( $dateformat,  strtotime( $product->get_auction_end_time() ));  ?>  <?php echo  date_i18n( $timeformat,  strtotime( $product->get_auction_end_time() ));  ?> <br />
  36.             <?php printf(__('Timezone: %s','wc_simple_auctions') , get_option('timezone_string') ? get_option('timezone_string') : __('UTC ','wc_simple_auctions').$gmt_offset) ?>
  37.         </p>
  38.  
  39.         <?php if ($product->get_auction_sealed() != 'yes'){ ?>
  40.             <p class="auction-bid"><?php echo $product->get_price_html() ?> </p>
  41.            
  42.             <?php if(($product->is_reserved() === TRUE) &&( $product->is_reserve_met() === FALSE )  ) : ?>
  43.                 <p class="reserve hold"  data-auction-id="<?php echo esc_attr( $product_id ); ?>" ><?php echo apply_filters('reserve_bid_text', __( "Reserve price has not been met", 'wc_simple_auctions' )); ?></p>
  44.             <?php endif; ?>
  45.            
  46.             <?php if(($product->is_reserved() === TRUE) &&( $product->is_reserve_met() === TRUE )  ) : ?>
  47.                 <p class="reserve free"  data-auction-id="<?php echo esc_attr( $product_id ); ?>"><?php echo apply_filters('reserve_met_bid_text', __( "Reserve price has been met", 'wc_simple_auctions' )); ?></p>
  48.             <?php endif; ?>
  49.         <?php } elseif($product->get_auction_sealed() == 'yes'){?>
  50.                 <p class="sealed-text"><?php echo apply_filters('sealed_bid_text', __( "This auction is <a href='#'>sealed</a>.", 'wc_simple_auctions' )); ?>
  51.                     <span class='sealed-bid-desc' style="display:none;"><?php _e( "In this type of auction all bidders simultaneously submit sealed bids so that no bidder knows the bid of any other participant. The highest bidder pays the price they submitted. If two bids with same value are placed for auction the one which was placed first wins the auction.", 'wc_simple_auctions' ) ?></span>
  52.                 </p>
  53.                 <?php
  54.                 if (!empty($product->get_auction_start_price())) {?>
  55.                     <?php if($product->get_auction_type() == 'reverse' ) : ?>
  56.                             <p class="sealed-min-text"><?php echo apply_filters('sealed_min_text', sprintf(__( "Maximum bid for this auction is %s.", 'wc_simple_auctions' ), wc_price($product ->get_auction_start_price()))); ?></p>
  57.                     <?php else : ?>
  58.                             <p class="sealed-min-text"><?php echo apply_filters('sealed_min_text', sprintf(__( "Minimum bid for this auction is %s.", 'wc_simple_auctions' ), wc_price($product ->get_auction_start_price()))); ?></p>         
  59.                     <?php endif; ?>        
  60.                 <?php } ?> 
  61.         <?php } ?> 
  62.  
  63.         <?php if($product->get_auction_type() == 'reverse' ) : ?>
  64.             <p class="reverse"><?php echo apply_filters('reverse_auction_text', __( "This is reverse auction.", 'wc_simple_auctions' )); ?></p>
  65.         <?php endif; ?>
  66.         <?php if ($product->get_auction_sealed() != 'yes'){ ?>
  67.             <?php if ($product->get_auction_proxy() &&  $product->get_auction_max_current_bider() && get_current_user_id() == $product->get_auction_max_current_bider()) {?>
  68.  
  69.                 <p class="max-bid"><?php  _e( $max_min_bid_text , 'wc_simple_auctions' ) ?> <?php echo wc_price($product->get_auction_max_bid()) ?>
  70.             <?php } ?>
  71.         <?php } elseif($user_max_bid > 0){ ?>
  72.             <p class="max-bid"><?php  _e( $max_min_bid_text , 'wc_simple_auctions' ) ?> <?php echo wc_price($user_max_bid) ?>
  73.         <?php } ?> 
  74.         <?php do_action('woocommerce_before_bid_form'); ?>
  75.  
  76.         <?php
  77.        
  78.         /* Check that prevents sellers / authors to bid on their own auctions */
  79.  
  80.         $author_id = get_the_author_meta("ID");
  81.  
  82.         if ($author_id != $current_user->ID): ?>
  83.  
  84.         <form class="auction_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo $product_id; ?>">
  85.            
  86.             <?php do_action('woocommerce_before_bid_button'); ?>
  87.            
  88.            
  89.            
  90.            
  91.             <input type="hidden" name="bid" value="<?php echo esc_attr( $product_id ); ?>" />  
  92.             <?php if($product->get_auction_type() == 'reverse' ) : ?>
  93.                 <div class="quantity buttons_added">
  94.                     <input type="button" value="+" class="plus" /> 
  95.                     <input type="number" name="bid_value" data-auction-id="<?php echo esc_attr( $product_id ); ?>"  <?php if ($product->get_auction_sealed() != 'yes'){ ?> value="<?php echo $product->bid_value() ?>" max="<?php echo $product->bid_value()  ?>"  <?php } ?> step="any" size="<?php echo strlen($product->get_curent_bid())+2 ?>" title="bid"  class="input-text  qty bid text left">
  96.                     <input type="button" value="-" class="minus" />
  97.                 </div> 
  98.                     <button type="submit" class="bid_button button alt"><?php echo apply_filters('bid_text', __( 'Bid', 'wc_simple_auctions' ), $product); ?></button>
  99.                            
  100.             <?php else : ?>
  101.                 <div class="quantity buttons_added">
  102.                     <input type="button" value="+" class="plus" />         
  103.                     <input type="number" name="bid_value" data-auction-id="<?php echo esc_attr( $product_id ); ?>" <?php if ($product->get_auction_sealed() != 'yes'){ ?>  value="<?php echo $product->bid_value()  ?>" min="<?php echo $product->bid_value()  ?>" <?php } ?>  step="any" size="<?php echo strlen($product->get_curent_bid())+2 ?>" title="bid"  class="input-text qty  bid text left">
  104.                     <input type="button" value="-" class="minus" />
  105.                 </div> 
  106.             <button type="submit" class="bid_button button alt"><?php echo apply_filters('bid_text', __( 'Bid', 'wc_simple_auctions' ), $product); ?></button>
  107.             <?php endif; ?>
  108.            
  109.             <input type="hidden" name="place-bid" value="<?php echo $product_id; ?>" />
  110.             <input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" />
  111.             <?php if ( is_user_logged_in() ) { ?>
  112.                 <input type="hidden" name="user_id" value="<?php echo  get_current_user_id(); ?>" />
  113.             <?php  } ?>
  114.             <?php do_action('woocommerce_after_bid_button'); ?>
  115.         </form>
  116.  
  117.         <?php else: ?>
  118.  
  119.             <?php echo __('You cannot bid on your own auctions.', 'wc_simple_auctions'); ?>
  120.  
  121.         <?php endif; ?>
  122.  
  123.         <?php do_action('woocommerce_after_bid_form'); ?>      
  124.        
  125.     </div>             
  126.  
  127. <?php elseif (($product->is_closed() === FALSE ) and ($product->is_started() === FALSE )):?>
  128.    
  129.     <div class="auction-time future" id="countdown"><?php echo apply_filters('auction_starts_text', __( 'Auction starts in:', 'wc_simple_auctions' ), $product); ?>
  130.         <div class="auction-time-countdown future" data-time="<?php echo $product->get_seconds_to_auction() ?>" data-format="<?php echo get_option( 'simple_auctions_countdown_format' ) ?>"></div>
  131.     </div>
  132.    
  133.     <p class="auction-starts"><?php echo apply_filters('time_text', __( 'Auction starts:', 'wc_simple_auctions' ), $product_id); ?> <?php echo  date_i18n( $dateformat,  strtotime( $product->get_auction_start_time() ));  ?>  <?php echo  date_i18n( $timeformat,  strtotime( $product->get_auction_start_time() ));  ?></p>
  134.     <p class="auction-end"><?php echo apply_filters('time_text', __( 'Auction ends:', 'wc_simple_auctions' ), $product_id); ?> <?php echo  date_i18n( $dateformat,  strtotime( $product->get_auction_end_time() ));  ?>  <?php echo  date_i18n( $timeformat,  strtotime( $product->get_auction_end_time() ));  ?> </p>
  135.    
  136. <?php endif;
  137.  
Add Comment
Please, Sign In to add comment