# fluent-booking/2.2.0/app/Hooks/Handlers/CleanupHandlers/BookingCleaner.php

Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution, version 2.2.0. 51 lines.

- Page: https://pluginprobe.com/plugins/fluent-booking/2.2.0/code/app/Hooks/Handlers/CleanupHandlers/BookingCleaner.php
- Raw: https://pluginprobe.com/plugins/fluent-booking/2.2.0/raw/app/Hooks/Handlers/CleanupHandlers/BookingCleaner.php
- Modified: 2025-08-28T13:55:42+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/fluent-booking/2.2.0/code/app/Hooks/Handlers/CleanupHandlers/BookingCleaner.php#L10-L20`.

```php
<?php

namespace FluentBooking\App\Hooks\Handlers\CleanupHandlers;

use FluentBooking\App\Models\BookingHost;

class BookingCleaner
{
    public function register()
    {
        add_action('fluent_booking/before_delete_booking', [$this, 'handleBeforeDelete'], 10, 1);
    }

    public function handleBeforeDelete($booking)
    {
        if (empty($booking)) {
            return;
        }

        BookingHost::query()->where('booking_id', $booking->id)->delete();

        if (defined('FLUENT_BOOKING_PRO_DIR_FILE')) {
            $order = \FluentBookingPro\App\Models\Order::query()
                ->where('parent_id', $booking->id)
                ->first();
    
            if (!$order) {
                return;
            }

            if ($order->items) {
                $order->items()->delete();
            }

            if ($order->discounts) {
                $order->discounts()->delete();
            }

            if ($order->transaction) {
                $order->transaction()->delete();
            }

            do_action('fluent_booking/before_delete_order', $order, $booking);

            $order->delete();

            do_action('fluent_booking/after_delete_order', $order, $booking);
        }
    }
}

```
