Lesson 51: Automatically Close Auctions After Expiry
I would revise Lesson 51 rather than discard it. The feature you implemented is still useful, but the title and objective should reflect what it actually does.
Revised Lesson 51
Lesson 51: Automatically Close Auctions After the End Time
What This Lesson Covers
In this lesson, we’ll make the auction system automatically recognize when an auction has reached its end time.
Instead of requiring an administrator to manually close auctions, the plugin will automatically update the auction status to closed whenever a visitor interacts with the auction after its scheduled end.
This prevents late bids from being accepted and ensures auctions finish at the correct time.
What We Implement
✔ Compare the current UTC time with the auction end time.
✔ Automatically change the auction status from active to closed.
✔ Prevent any future bids from being accepted.
✔ Keep the auction data intact for later display.
Why This Matters
Without automatic closure:
- Auctions could remain active indefinitely.
- Users might continue placing bids after the deadline.
- Administrators would have to close every auction manually.
With this improvement:
- Auctions close themselves automatically.
- The database always reflects the correct status.
- The bidding system becomes much more reliable.
What We Did
Inside the bid validation process, we checked whether the auction had already expired.
If the current UTC time is greater than or equal to the auction end time, we immediately update the auction status.
Example:
if ( strtotime( gmdate( 'Y-m-d H:i:s' ) ) >= strtotime( $auction->auction_end ) ) {
$wpdb->update(
$auction_table,
array(
'status' => 'closed',
),
array(
'id' => $auction_id,
),
array(
'%s',
),
array(
'%d',
)
);
return false;
}
What Happens Now
If a visitor attempts to place a bid after the auction has ended:
- The plugin checks the auction end time.
- The auction status is automatically updated to closed.
- The bid is rejected.
- Future visitors will also see the auction as closed.
Current Limitation
At this stage, a closed auction is no longer displayed by the frontend shortcode.
While this successfully prevents further bidding, it also hides the auction from visitors.
We’ll improve this behavior in the next lesson.
Next Lesson
Lesson 52: Display Closed Auctions with Winner Information
Instead of hiding completed auctions, we’ll:
- Display an Auction Closed badge.
- Show the winning bidder.
- Display the winning bid.
- Keep the bid history visible.
- Hide only the bidding form.
- Create a permanent auction record for visitors.
