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
$response = wp_remote_post('https://api.deliveryzone.fi/api/v1/delivery/check', [
'headers' => [
'X-Api-Key' => get_option('dz_api_key'),
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'destinationPostcode' => $postcode,
'basketValueCents' => $basket_cents,
]),
]);
$data = json_decode(wp_remote_retrieve_body($response), true);
When canDeliver is false (or null), the response includes a reasonCode field. Display this to the customer:
NOT_DELIVERABLE — postcode is outside your delivery zones, or not recognised (the API intentionally uses one generic code for both, to protect zone boundaries)MINIMUM_ORDER_NOT_MET — basket value is below the zone's minimum orderBASKET_VALUE_REQUIRED — a basket value is needed to evaluate this destination's minimum-order or free-delivery ruleAlways handle HTTP errors (5xx, timeout) gracefully. If the API is unreachable, fail safe — either reject the order or allow manual review.
Free plan. No credit card. Real setup help.