The Delivery Zone API integrates with WooCommerce through the woocommerce_package_rates filter. Call the API server-side during shipping rate calculation to validate the destination postcode and return the correct price.
Call the API inside the woocommerce_package_rates or woocommerce_cart_shipping_packages filter — before shipping rates are returned to the customer.
// PHP — server-side, keep API key out of frontend
$r = wp_remote_post('https://api.deliveryzone.fi/v1/check', [
'headers' => [
'X-Api-Key' => get_option('dz_api_key'),
'Content-Type' => 'application/json',
],
'body' => json_encode([
'destinationPostcode' => $postcode,
'basketValueCents' => $basketCents,
]),
]);
$data = json_decode(wp_remote_retrieve_body($r), true);
if (!$data['canDeliver']) return [];
foreach ($rates as $rate) {
$rate->cost = $data['priceCents'] / 100;
}
When canDeliver is false, the response includes a reason field. Display this to the customer:
OUT_OF_ZONE — postcode is valid but outside all defined zonesUNKNOWN_POSTCODE — postcode is not recognisedMIN_BASKET — basket value is below the zone minimumAlways handle HTTP errors (5xx, timeout) gracefully. If the API is unreachable, fail safe — either reject the order or allow manual review.
wp_remote_post errors and timeouts gracefullyCreate a free account and get your sandbox API key in minutes.