Shipping rules can quickly become complex—especially when you need to restrict delivery based on ZIP or postcode. Whether you’re running a local WooCommerce store, managing region-specific logistics, or optimizing checkout conversions, postcode-based shipping control is essential.
In this tutorial, I’ll walk you through three reliable ways to restrict shipping by postcode in WooCommerce, ranging from no-code to fully programmatic solutions. These approaches are commonly implemented by an experienced WooCommerce Developer or WordPress Developer, and scale well when built by a Full Stack Developer like Deepak Gupta.
In this guide, you’ll learn:
- How to restrict shipping using WooCommerce shipping zones
- How to control shipping methods via a lightweight conditional plugin
- How to restrict shipping programmatically using custom code
Let’s dive in 👇
Method 1: Restrict Shipping by Postcode Using a Custom Shipping Zone
If your requirements are straightforward, WooCommerce’s built-in Shipping Zones may be all you need.
Steps:
- Go to WooCommerce → Settings → Shipping → Shipping Zones
- Click Add zone
- Enter a zone name (e.g., “Local Delivery Area”)
- In Zone regions, select Limit to specific ZIP/postcodes
- Add your postcodes
Supported formats:
- Single codes:
0108,0107 - Ranges:
0101...0109 - Wildcards:
010*(covers 0100–0109)
Once the zone is created, assign shipping methods (Flat Rate, Free Shipping, etc.) to that zone.
Important:
This method doesn’t restrict existing shipping methods—it creates new shipping rules for the defined postcodes. For many stores, this is perfectly sufficient.
✅ Best for: Simple regional shipping rules
❌ Limitation: Less flexible for complex logic
Method 2: Restrict Shipping Methods by Postcode Using a Plugin
If you want to keep your existing shipping methods intact but enable or disable them conditionally, a conditional shipping plugin is a better fit.
A lightweight plugin like Simple Conditional Shipping and Payments allows you to:
- Enable or disable shipping methods by postcode
- Use billing or shipping postcode
- Combine multiple conditions using AND logic
- Apply similar rules to payment methods
How it works:
- Go to WooCommerce → Settings → Conditions
- Open Shipping Conditions
- Add a new rule
- Choose:
- Condition: Billing or Shipping Postcode
- Action: Enable or Disable Shipping Method
- Save the rule
This approach is often recommended by a professional WooCommerce Developer because it avoids unnecessary theme or core modifications.
✅ Best for: Stores needing flexibility without custom code
❌ Limitation: Still relies on a plugin
Method 3: Restrict WooCommerce Shipping by Postcode Programmatically (Custom Code)
For maximum control, performance, and scalability, a programmatic approach is ideal. This is the preferred solution for advanced stores built by a MERN Stack Developer or Full Stack Developer.
Below is a custom PHP snippet that restricts a specific shipping method to selected postcodes.
Code Snippet
/**
* Restrict a shipping method to specific postcodes
*/
add_filter( 'woocommerce_package_rates', 'restrict_shipping_by_postcodes', 25, 2 );
function restrict_shipping_by_postcodes( $rates, $package ) {
$allowed_postcodes = array(
'0108',
'0107',
);
$restricted_shipping_method_type = 'flat_rate';
$restricted_shipping_method_id = 2;
// Final rate ID example: flat_rate:2
$restricted_shipping_method = "{$restricted_shipping_method_type}:{$restricted_shipping_method_id}";
$customer_postcode = WC()->customer->get_shipping_postcode();
foreach ( $rates as $rate_id => $rate ) {
if ( $rate_id !== $restricted_shipping_method ) {
continue;
}
if ( ! in_array( $customer_postcode, $allowed_postcodes ) ) {
unset( $rates[ $rate_id ] );
}
}
return $rates;
}
Key notes:
- Uses the
woocommerce_package_ratesfilter (the correct hook for shipping logic) $allowed_postcodesdefines where the method is available- Shipping method ID combines method type + numeric ID
- Supports billing or shipping postcode
- Lightweight and performance-friendly
This approach avoids plugin overhead and integrates cleanly with WooCommerce core—something an experienced WordPress Developer like Deepak Gupta prioritizes.
✅ Best for: Custom, high-performance WooCommerce stores
❌ Limitation: Requires development expertise
Which Method Should You Choose?
| Requirement | Best Method |
|---|---|
| Simple postcode rules | Shipping Zones |
| Conditional logic without code | Plugin |
| Performance & scalability | Custom Code |
Final Thoughts
Restricting shipping by postcode in WooCommerce isn’t just a configuration task—it’s a checkout optimization decision. Poor implementation can break shipping, confuse customers, or hurt conversions.
Whether you choose a built-in setting, a plugin, or a custom solution, the key is aligning the method with your store’s complexity and growth plans.
For scalable, clean, and future-proof WooCommerce solutions, working with a WooCommerce Developer, WordPress Developer, or Full Stack Developer like Deepak Gupta ensures your shipping logic works reliably—today and as your store grows
Additional Charges on WC Checkout is a powerful extension plugin for WooCommerce that allows administrators to add fees to a customer’s order total dynamically. You can check it out here.
Please leave a comment below if you have any questions.
Hi and welcome! I’ve spent more than 7 years helping WordPress users with easy-to-follow guides, tutorials, and practical tips all completely free.
Need expert developer help? I’m just a message away.