I have a car rent site where people can book a car for their needs,but problem is my vehicles are limited so after booking a car i want to show an alert for the next 1 hour as it is overbooked immediately to my customers as no one can book it again within next 1 hour. Here is my approach-
now problem is how can I remove this MSG after 1 hour?
any code example would be highly appreciated. Thanks
You can use set_transient
function after someone booked a car. I assume a car is post type and all post have a unique ID. So after a car is booked you create a transient which expires after one hour. Check Documentation. Your code might have the next logic.
set_transient( $post_id . '_car_is_booked', true, HOUR_IN_SECONDS );
You set transient for HOUR_IN_SECONDS
it is a special WordPress variable and after one hour it will be removed from the database automatically. So to find our is this car is booked or not you can use function get_transient
get_transient Docs.
// return false if option does not exists
get_transient( $post_id . '_car_is_booked' );
And if transient
for specific post ID exists it means the car is booked less then one hour ago.