# yatra/3.0.8/app/Hooks/SavedTripHooks.php

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.8. 39 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.8/code/app/Hooks/SavedTripHooks.php
- Raw: https://pluginprobe.com/plugins/yatra/3.0.8/raw/app/Hooks/SavedTripHooks.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.8/code/app/Hooks/SavedTripHooks.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Yatra\Hooks;

use Yatra\Repositories\SavedTripRepository;

/**
 * Saved Trip (Wishlist) Hooks
 *
 * Keeps the wishlist meta in sync with the trip lifecycle: when a trip is
 * deleted, its ID is purged from every user's saved-trips meta so orphan
 * IDs don't accumulate forever.
 */
class SavedTripHooks
{
    public static function init(): void
    {
        add_action('yatra_trip_deleted', [self::class, 'onTripDeleted'], 10, 1);
    }

    /**
     * Garbage-collect a deleted trip's ID from every user's wishlist.
     */
    public static function onTripDeleted($tripId): void
    {
        $tripId = (int) $tripId;
        if ($tripId <= 0) {
            return;
        }
        try {
            (new SavedTripRepository())->removeTripFromAllUsers($tripId);
        } catch (\Throwable $e) {
            // Don't let cleanup failure break the trip-delete flow.
        }
    }
}

```
