wpgenie

faq13 - anti snipping / extend auction end time

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×