Remove "Cancel Booking" in some cases

Hello,

I want the “Cancel booking” button to be cleared when the payment is: pending or when the booking is paid. To force users to request cancellation via my contact page.
I’ve tried this code but it doesn’t work:

add_filter(
    'hivepress/v1/templates/booking_view_page/blocks',
    function ($blocks, $template){

        $order = $template->get_context('order');

        if(!$order){
            return $blocks;
        }

        $order_status = $order->get_status();

        $allowed_statuses = array('pending payment', 'failed', 'processing', 'completed', 'on hold', 'awaiting payment', 'cancelled');

        if(!in_array($order_status, $allowed_statuses)){
            return $blocks;
        }

        return hivepress()->helper->merge_trees(
                    [ 'blocks' => $blocks ],
                    [
                        'blocks' => [
                            'booking_cancel_link' => [
                                'type' => 'content',
                            ],
                        ],
                    ]
                )['blocks'];
    },
    1000,
    2
);

Hi,

The code snippet seems to be ok, please try debugging it by adding var_dump or error_log on different lines to check where the code breaks. A list of statuses may be incorrect, for the HivePress order object they have the wc- prefix and no spaces, e.g. wc-completed.

Hope this helps.