<?php

declare (strict_types=1);
namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout;

use WC_Order;
/**
 * Finds WooCommerce orders by UCP checkout session ID.
 */
final class CheckoutOrderFinder
{
    public function find_by_checkout_id(string $session_id): ?WC_Order
    {
        $orders = \wc_get_orders(['meta_key' => '_ucp_checkout_id', 'meta_value' => $session_id, 'meta_compare' => '=', 'limit' => 1, 'return' => 'objects']);
        if (empty($orders)) {
            return null;
        }
        return $orders[0] instanceof WC_Order ? $orders[0] : null;
    }
}
