Lesson 50 Implementation: Prevent Last-Second Bid Sniping with Automatic Auction Time Extension

One of the biggest frustrations in online auctions is bid sniping—when someone waits until the final few seconds before placing a bid, leaving other bidders with no opportunity to respond. Many professional auction platforms solve this by automatically extending the auction if a bid is received near the end.

In this lesson, we implemented the same feature in the Flipnzee Auctions plugin. Whenever a valid bid is placed during the final 60 seconds of an auction, the auction end time is automatically extended by five minutes.


What We Built

The auction system now:

  • Detects every successful bid.
  • Checks how much time remains before the auction ends.
  • If 60 seconds or less remain:
    • Extends the auction by five minutes.
    • Updates the auction end time in the database.
  • Otherwise, the auction continues normally.

This gives every interested bidder a fair opportunity to respond.


Step 1: Locate the Bid Processing Method

Open:

includes/class-bid-manager.php

Locate:

public static function place_bid(

This method already:

  • validates bids,
  • inserts the bid into the database,
  • updates the auction’s current highest bid.

Step 2: Keep the Existing Current Bid Update

After a successful bid, the plugin already updates the auction table.

$wpdb->update(
    $auction_table,
    array(
        'current_bid' => $bid_amount,
    ),
    array(
        'id' => $auction_id,
    ),
    array(
        '%f',
    ),
    array(
        '%d',
    )
);

Immediately after this block, we inserted the anti-sniping logic.


Step 3: Retrieve the Auction End Time

First, fetch the current auction end time.

$auction = $wpdb->get_row(
    $wpdb->prepare(
        "SELECT auction_end
        FROM {$auction_table}
        WHERE id = %d",
        $auction_id
    )
);

This retrieves the existing end time directly from the database.


Step 4: Calculate Remaining Time

Convert the auction end time into a Unix timestamp.

$end_time = strtotime(
    $auction->auction_end
);

$current_time = current_time(
    'timestamp'
);

$seconds_left =
    $end_time - $current_time;

Using timestamps makes it easy to compare dates mathematically.


Step 5: Detect Last-Minute Bids

Only extend the auction if less than one minute remains.

if ( $seconds_left <= 60 ) {

    // Extend auction
}

This prevents unnecessary extensions while protecting against last-second sniping.


Step 6: Extend the Auction

Add five minutes to the existing end time.

$new_end = date(
    'Y-m-d H:i:s',
    $end_time + ( 5 * 60 )
);

Notice that:

5 × 60 = 300 seconds

The new end time is generated in MySQL datetime format.


Step 7: Save the New Auction End Time

Update the auction record.

$wpdb->update(
    $auction_table,
    array(
        'auction_end' => $new_end,
    ),
    array(
        'id' => $auction_id,
    ),
    array(
        '%s',
    ),
    array(
        '%d',
    )
);

The countdown timer will now use this updated value.


Complete Anti-Sniping Code

/*
 * Anti-sniping:
 * Extend auction by 5 minutes if
 * less than 60 seconds remain.
 */
$auction = $wpdb->get_row(
    $wpdb->prepare(
        "SELECT auction_end
        FROM {$auction_table}
        WHERE id = %d",
        $auction_id
    )
);

if ( $auction ) {

    $end_time = strtotime(
        $auction->auction_end
    );

    $current_time = current_time(
        'timestamp'
    );

    $seconds_left =
        $end_time - $current_time;

    if ( $seconds_left <= 60 ) {

        $new_end = date(
            'Y-m-d H:i:s',
            $end_time + ( 5 * 60 )
        );

        $wpdb->update(
            $auction_table,
            array(
                'auction_end' => $new_end,
            ),
            array(
                'id' => $auction_id,
            ),
            array(
                '%s',
            ),
            array(
                '%d',
            )
        );
    }
}

Why This Feature Matters

Many professional auction websites use automatic auction extensions because they:

  • Prevent unfair last-second bidding.
  • Give genuine buyers time to react.
  • Encourage competitive bidding.
  • Increase seller confidence.
  • Often lead to higher final selling prices.

Instead of rewarding the fastest click during the final seconds, the auction rewards the highest genuine bidder.


Testing

Although this lesson was successfully implemented, testing was intentionally postponed.

Because auction end times depend on server time and WordPress timezone settings, it is more practical to verify the feature during a real auction approaching its end. When a bid is placed within the final 60 seconds, the auction end time should automatically increase by five minutes.

Download Source Code

Download the starting version of the plugin before the lesson:

⬇ Download Plugin (After Lesson 49) (0 downloads )

Download the completed version after this lesson:


What We Learned

In this lesson we learned how to:

  • Improve auction fairness with anti-sniping logic.
  • Work with Unix timestamps in PHP.
  • Calculate remaining auction time.
  • Update MySQL datetime values.
  • Extend auction durations dynamically.
  • Build a feature commonly found in commercial auction platforms.

Final Thoughts

A simple five-minute extension can significantly improve the fairness and competitiveness of an online auction. By adding anti-sniping protection, Flipnzee Auctions now behaves much more like established auction marketplaces, ensuring that every bidder has a reasonable opportunity to respond before an auction closes.

Leave a Reply