dongxu4023 2019-05-05 03:54
浏览 27
已采纳

如何摆脱超额预订的汽车租赁网站

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-

  • fetching only today's booking info
  • checking every vehicle is it 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 MSG after 1 hour?

any code example would be highly appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • duanbi3786 2019-05-05 09:11
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VS2022 C++的相关代码问题咨询
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥30 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码