Advertisement
wpgenie

faq13 - anti snipping / extend auction end time

Mar 13th, 2018 (edited)
3,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. /* visit us - https://wpgenie.org */
  2.  
  3. /* Auto Extend Auction by 2 min when a bid is placed within the last 5mins */
  4. add_action( 'woocommerce_simple_auctions_outbid', 'woocommerce_simple_auctions_extend_time', 50 );
  5. add_action( 'woocommerce_simple_auctions_proxy_outbid', 'woocommerce_simple_auctions_extend_time', 50 );
  6.  
  7.  
  8. function woocommerce_simple_auctions_extend_time($data) {
  9.  
  10.     $product = get_product( $data['product_id'] );
  11.  
  12.     if ('auction' === $product->get_type() ) {
  13.         $auctionend = new DateTime($product->get_auction_dates_to());
  14.         $auctionendformat = $auctionend->format('Y-m-d H:i:s');
  15.         $time = current_time( 'timestamp' );
  16.         $timeplus5 = date('Y-m-d H:i:s', strtotime('+5 minutes', $time)); // if bid is placed in less than 5 minutes before auction end time
  17.  
  18.         if ($timeplus5 > $auctionendformat) {
  19.             $auctionend->add(new DateInterval('PT120S')); // extend auction end time for 120 seconds
  20.             update_post_meta( $data['product_id'], '_auction_dates_to', $auctionend->format('Y-m-d H:i:s') );
  21.             // wc_add_notice(sprintf(__('Anti snipping enabled - auction end time extended for 2 minutes', 'wc_simple_auctions')), 'notice'); // optional, uncomment to use
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement