# yatra/3.0.14.2/app/Services/ReviewReminderService.php

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.14.2. 113 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.14.2/code/app/Services/ReviewReminderService.php
- Raw: https://pluginprobe.com/plugins/yatra/3.0.14.2/raw/app/Services/ReviewReminderService.php
- Modified: 2026-05-25T04:28:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.14.2/code/app/Services/ReviewReminderService.php#L10-L20`.

```php
<?php
/**
 * Review Reminder Service
 * 
 * Handles sending review reminders to customers
 * 
 * @package Yatra\Services
 * @since 3.0.0
 */

declare(strict_types=1);

namespace Yatra\Services;

class ReviewReminderService
{
    /**
     * Schedule review reminder for a booking
     * 
     * @param int $bookingId Booking ID
     */
    public static function scheduleReminder(int $bookingId): void
    {
        // Check if reviews are enabled
        if (!SettingsService::reviewsEnabled()) {
            return;
        }
        
        $reminder_days = SettingsService::getInt('review_reminder_days', 7);
        
        if ($reminder_days <= 0) {
            return;
        }
        
        // Schedule reminder using WordPress cron
        $timestamp = time() + ($reminder_days * DAY_IN_SECONDS);
        
        if (!wp_next_scheduled('yatra_send_review_reminder', [$bookingId])) {
            wp_schedule_single_event($timestamp, 'yatra_send_review_reminder', [$bookingId]);
        }
    }
    
    /**
     * Send review reminder email
     * 
     * @param int $bookingId Booking ID
     */
    public static function sendReminder(int $bookingId): void
    {
        $bookingRepository = new \Yatra\Repositories\BookingRepository();
        $booking = $bookingRepository->findWithTrip($bookingId);

        if (!$booking || empty($booking->contact_email)) {
            return;
        }

        // Check if customer has already reviewed
        if (self::hasCustomerReviewed($bookingId, (int) ($booking->customer_id ?? 0))) {
            return;
        }

        // Get trip details
        $tripRepository = new \Yatra\Repositories\TripRepository();
        $trip = $tripRepository->find((int) ($booking->trip_id ?? 0));

        if (!$trip) {
            return;
        }

        $review_url = get_permalink($trip->id) . '#reviews';
        $vars = TransactionalEmailTemplateService::variablesFromBooking($booking);
        $vars['review_url'] = esc_url($review_url);
        $vars['completion_date'] = date_i18n(get_option('date_format'));

        TransactionalEmailTemplateService::sendIfEnabled(
            TransactionalEmailTemplateService::TYPE_REVIEW_REQUEST,
            (string) $booking->contact_email,
            $vars
        );
    }
    
    /**
     * Check if customer has already reviewed the trip
     * 
     * @param int $bookingId Booking ID
     * @param int $customerId Customer ID
     * @return bool
     */
    private static function hasCustomerReviewed(int $bookingId, int $customerId): bool
    {
        global $wpdb;
        
        $reviewsTable = \Yatra\Database\Tables\ReviewsTable::getTableName();
        
        $count = $wpdb->get_var($wpdb->prepare(
            "SELECT COUNT(*) FROM {$reviewsTable} 
             WHERE booking_id = %d OR customer_id = %d",
            $bookingId,
            $customerId
        ));
        
        return $count > 0;
    }
    
    /**
     * Initialize review reminder cron
     */
    public static function init(): void
    {
        add_action('yatra_send_review_reminder', [self::class, 'sendReminder']);
    }
}

```
