Thanks for this @macman43 I don’t understand how you were able to add states in the zip code field. Are you using a 3rd party app for that? that’s not native to WooCommerce core.
I believe you cut off the List Per Postcode. Normally, we do the entire US and then write a hook or use a 3rd party app to block those two states. I’m not aware of any app, I’m a developer, so I can only offer a hook.
What I would do if you want is change the Zone Region be “United States” then add this snippet to your functions.php file near the bottom. This will block those two states. Then put a notice on the checkout page and shipping policy page that denotes AK and HI are not eligible for Free Shipping.
function custom_disable_free_shipping_for_specific_states($rates, $package) {
$restricted_states = array('AK', 'HI'); // Alaska and Hawaii
// Check the destination state of the package
if (isset($package['destination']['state']) && in_array($package['destination']['state'], $restricted_states)) {
// Loop through the available shipping rates
foreach ($rates as $rate_id => $rate) {
// If a free shipping method is found, remove it
if ('free_shipping' === $rate->method_id) {
unset($rates[$rate_id]);
}
}
}
return $rates;
}
add_filter('woocommerce_package_rates', 'custom_disable_free_shipping_for_specific_states', 10, 2);
How to Add the Code:
1.) Go to your WordPress dashboard.
2.) Navigate to Appearance > Theme Editor or use a code editor if you have access to the server files.
3.) Open the functions.php file of your active theme.
4.) Copy and paste the provided code into the functions.php file.
5.) Save the changes.
Or use FTP (safest method)
This code will ensure that free shipping is not available for orders shipping to Alaska or Hawaii. Let me know if you need any more help with this!
-
This reply was modified 10 months ago by
Stef.