Free and Premium WordPress Plugins & Themes Forums WordPress Plugins Hotel Booking Custom notifications based on booking date
- This topic has 1 reply, 2 voices, and was last updated 1 month, 1 week ago by J. Davis.
- AuthorPosts
- October 9, 2024 at 4:56 am #1678783We ConsultParticipant
Good day.
I need an ability to remind a guest to pay a deposit within 2 days after booking. I’m no code guru and am kindly asking you review you to and tell me if I’m smoking something cheap or onto something:
<?php
// Hook into the booking creation process to schedule the reminder
add_action(‘mphb_booking_created’, ‘schedule_payment_reminder’);function schedule_payment_reminder($booking_id) {
// Schedule the event to trigger after 2 days
if (!wp_next_scheduled(‘send_payment_reminder_event’, array($booking_id))) {
wp_schedule_single_event(time() + 2 * DAY_IN_SECONDS, ‘send_payment_reminder_event’, array($booking_id));
}
}// Event handler to send the reminder if the booking is still pending
add_action(‘send_payment_reminder_event’, ‘send_payment_reminder’, 10, 1);function send_payment_reminder($booking_id) {
// Get booking details
$booking = mphb_get_booking($booking_id);// Check if the booking is still pending
if ($booking->get_status() === ‘pending’) {
// Get guest email
$guest_email = $booking->get_customer_email();// Prepare the email content
$subject = ‘Payment Reminder for Your Booking’;
$message = sprintf(
‘Dear %s, this is a reminder to complete the payment for your booking (ID: %d). Please visit our site to finalize your payment.’,
$booking->get_customer_full_name(),
$booking_id
);// Send the email
wp_mail($guest_email, $subject, $message);
}
}// Optional: Cleanup scheduled events if the booking is paid
add_action(‘mphb_booking_status_changed’, ‘cleanup_scheduled_reminder’, 10, 2);function cleanup_scheduled_reminder($booking_id, $new_status) {
if ($new_status !== ‘pending’) {
// Clear the scheduled event if the booking is no longer pending
$timestamp = wp_next_scheduled(‘send_payment_reminder_event’, array($booking_id));
if ($timestamp) {
wp_unschedule_event($timestamp, ‘send_payment_reminder_event’, array($booking_id));
}
}
}
?>Thank you in advance…
October 10, 2024 at 1:59 am #1679209J. DavisKeymasterHi, We do not provide customizations or consultations of this type as all our developers are involved in the development process. You may check the documentation of our Payment Request add-on to learn its capabilities https://motopress.com/document/hotel-booking-payment-request/
- AuthorPosts
- You must be logged in to reply to this topic.