# fluent-booking/2.5.0/app/Hooks/Handlers/CleanupHandlers/OrderCleaner.php

Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution, version 2.5.0. 33 lines.

- Page: https://pluginprobe.com/plugins/fluent-booking/2.5.0/code/app/Hooks/Handlers/CleanupHandlers/OrderCleaner.php
- Raw: https://pluginprobe.com/plugins/fluent-booking/2.5.0/raw/app/Hooks/Handlers/CleanupHandlers/OrderCleaner.php
- Modified: 2024-07-16T14:25:14+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.5.0/code/app/Hooks/Handlers/CleanupHandlers/OrderCleaner.php#L10-L20`.

```php
<?php

namespace FluentBooking\App\Hooks\Handlers\CleanupHandlers;

use FluentBooking\App\Models\Booking;
use FluentBookingPro\App\Models\Transactions;
use FluentBookingPro\App\Models\OrderItems;

class OrderCleaner
{
    public function register()
    {
        add_action('fluent_booking/before_delete_order', [$this, 'handleBeforeDelete'], 10, 2);
    }

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

        Transactions::query()
            ->where('object_type', 'order')
            ->where('object_id', $order->id)
            ->delete();

        OrderItems::query()->where('order_id', $order->id)
            ->when($booking, function ($query, $booking) {
                $query->where('booking_id', $booking->id);
            })->delete();

    }
}
```
