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']); } }