Woo Disable Shipping Zone to User Roles
WordPress/WooCommerce plugin for B2B stores that lets you associate each user role with one or more permitted shipping zones. Logged-in users can only ship to countries included in the zones configured for their role.
by Accorinti Lorenzo · github.com/accolore/woo-disable-shipping-zone-to-useroles · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/accolore/woo-disable-shipping-zone-to-useroles/archive/refs/heads/main.zipWordPress/WooCommerce plugin for B2B stores that lets you associate each user role with one or more permitted shipping zones. Logged-in users can only ship to countries included in the zones configured for their role.
Requirements
- WordPress 6.0+
- PHP 7.4+
- WooCommerce 7.0+
- HPOS (High-Performance Order Storage) compatible
Installation
- Copy the
woo-disable-shipping-zone-to-userolesfolder towp-content/plugins/. - Activate the plugin from Plugins → Installed Plugins.
- Make sure WooCommerce is installed and active.
- Configure the rules from WooCommerce → Settings → Shipping → Shipping Zone Roles.
Use case
Designed for B2B sites where each customer has a dedicated role that identifies their commercial region (e.g. Italy, Europe, USA, Japan, rest of world).
Example: a user with the it_customer role can only ship within the "Italy" zone. They cannot select a checkout country from another zone (e.g. Germany). To ship elsewhere, an administrator must assign them a different role.
Configuration
Prerequisites
Before configuring the plugin:
- Create the required user roles (via a role management plugin or custom code).
- Configure shipping zones under WooCommerce → Settings → Shipping → Shipping zones.
Roles and zones are loaded dynamically from the site — the plugin contains no predefined lists.
Settings page
Go to WooCommerce → Settings → Shipping → Shipping Zone Roles.
Direct URL:
/wp-admin/admin.php?page=wc-settings&tab=shipping§ion=zone-roles
For each row you can define:
| Field | Description |
|---|---|
| Role | User role, chosen from all roles registered on the site |
| Permitted shipping zones | One or more WooCommerce shipping zones allowed for that role |
Available actions:
- Add row — adds a new configuration row
- Remove — removes a row
- Save changes — saves all rules (WooCommerce settings button at the bottom of the page)
Example configuration
| Role | Permitted zones |
|---|---|
it_customer |
Italy zone |
eu_customer |
Europe zone |
us_customer |
USA zone |
row_customer |
Locations not covered by your other zones |
Actual role and zone names depend on your site configuration.
Multiple rules
- Same role on multiple rows: permitted zones are merged automatically on save.
- User with multiple configured roles: can ship to the union of zones from all applicable roles.
- Role without rules: no restriction is applied to that user.
Checkout behaviour
The plugin applies three levels of control, from most proactive to most defensive:
1. UI prevention
The Shipping country dropdown only shows countries belonging to the permitted zones for the logged-in user's role. Non-allowed countries are not selectable.
2. Checkout validation
- On every AJAX checkout form update, the country is validated.
- On order submission, the country is checked again.
- If the country is not allowed, the order is rejected with an error message.
3. Shipping method filter
If an unauthorized country somehow bypasses the previous checks, shipping methods are removed as a final safeguard.
User message
When shipping to a country is not allowed, the user sees a message such as:
Shipping to the selected country is not available for your account. Please contact the store administrator if you need to change your shipping region.
Handled scenarios
| Scenario | Behaviour |
|---|---|
| User tries to select a non-permitted country | Country does not appear in the dropdown |
| User with a saved address in a non-permitted country | Checkout rejected with an error message |
| Form manipulation (POST/AJAX) | Order blocked during validation |
| Postcode/city change within the same permitted country | No additional restriction |
Internationalization
- Text domain:
woo-disable-shipping-zone-to-useroles - Template file:
languages/woo-disable-shipping-zone-to-useroles.pot - Italian translation:
languages/woo-disable-shipping-zone-to-useroles-it_IT.po
To enable translations in production, compile the .mo file from the .po or use a plugin such as Loco Translate.
Developer extensions
Filter selectable roles in admin
add_filter( 'wdszur_admin_selectable_roles', function ( array $roles ): array {
unset( $roles['administrator'], $roles['shop_manager'] );
return $roles;
} );
Allows excluding system roles from the configuration dropdown without modifying the plugin code.
Configuration option
Rules are stored in the WordPress option wdszur_rules:
[
[
'role' => 'it_customer',
'allowed_zones' => [ 1 ],
],
]
role— WordPress role slugallowed_zones— array of WooCommerce zone IDs (0= "Rest of the world")
WooCommerce hooks used
| Hook | Purpose |
|---|---|
woocommerce_countries_shipping_countries |
Limits selectable checkout countries |
woocommerce_checkout_update_order_review |
Validates country on every AJAX update |
woocommerce_after_checkout_validation |
Blocks order on submit if country is not allowed |
woocommerce_package_rates |
Removes shipping methods as defense in depth |
woocommerce_no_shipping_available_html |
Custom message when no shipping methods are available |
Admin integration hooks
| Hook | Purpose |
|---|---|
woocommerce_get_sections_shipping |
Registers the "Shipping Zone Roles" section |
woocommerce_settings_shipping |
Renders the section content |
woocommerce_update_options_shipping |
Saves rules on form submit |
Plugin structure
woo-disable-shipping-zone-to-useroles/
├── woo-disable-shipping-zone-to-useroles.php # Bootstrap
├── includes/
│ ├── class-plugin.php
│ ├── class-rules-repository.php
│ ├── class-user-role-resolver.php
│ ├── class-zone-resolver.php
│ ├── class-checkout-country-restrictor.php
│ └── class-shipping-filter.php
├── admin/
│ ├── class-settings-page.php
│ ├── class-admin-data-provider.php
│ ├── views/settings-page.php
│ └── assets/
├── languages/
└── README.md
Important notes
- The plugin is designed for B2B sites with registered, authenticated users. Guest users are not restricted.
- Roles and zones are never hardcoded — they are always read from the host site configuration.
- The plugin does not modify WooCommerce core classes; it uses native hooks only.
- If a configured role or zone is removed from the site, associated rules are ignored at runtime until updated from the settings page.
Author
Accorinti Lorenzo — vision.ego.it
License
Distributed under the same license as the WordPress plugin.