Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this questionI have a car rent site where people can book a car for their needs. The problem is my vehicles are limited so after booking a car I want to immediately show an alert for the next 1 hour that it is overbooked so no one can book it again within that hour.
Here is my approach-
- Fetching only today's booking info
- Checking whether every vehicle is booked or not
- If it is booked, then count the booking time and current time and compare them. Is it equal to or less then 1 hour?
- If it returns true then show the alert
Now problem is how can I remove this message after 1 hour?
Any code example would be highly appreciated. Thanks
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this questionI have a car rent site where people can book a car for their needs. The problem is my vehicles are limited so after booking a car I want to immediately show an alert for the next 1 hour that it is overbooked so no one can book it again within that hour.
Here is my approach-
- Fetching only today's booking info
- Checking whether every vehicle is booked or not
- If it is booked, then count the booking time and current time and compare them. Is it equal to or less then 1 hour?
- If it returns true then show the alert
Now problem is how can I remove this message after 1 hour?
Any code example would be highly appreciated. Thanks
Share Improve this question edited May 6, 2019 at 0:25 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked May 5, 2019 at 5:16 Mahbub AnsaryMahbub Ansary 312 bronze badges 2- 1 Hi. Thanks for your question, but... How is that connected with WordPress exactly? – Krzysiek Dróżdż Commented May 5, 2019 at 6:51
- How did you checked and show the message? – Vishwa Commented May 5, 2019 at 9:11
1 Answer
Reset to default 1Guys found the solution at **stackoverflow**
:
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.