--- a/runtime/delivery.php +++ b/runtime/delivery.php @@ -1,10 +1,18 @@ 4]); - if (is_wp_error($response)) return []; + if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) return []; $body = json_decode(wp_remote_retrieve_body($response), true); - return $body['countries'] ?? []; + if (($body['schema'] ?? null) !== 2 || !is_array($body['destinations'] ?? null)) return []; + $countries = array_values(array_filter($body['destinations'], function ($country) { + return is_string($country) && preg_match('/^[A-Z]{2}$/D', $country); + })); + if (!$countries) return []; + set_transient('velquorra_delivery_regions_v2', $countries, 5 * MINUTE_IN_SECONDS); + return $countries; } add_action('woocommerce_before_calculate_totals', function () { // The delivery notice and checkout use the same eligibility lookup.