Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Filter WooCommerce shipping methods depending of state in address
/* WooCommerce check for states Florida, Alabama, Georgia, Tennessee, South Carolina, North Carolina,
* Kentucky, Washington D.C., Virginia, and remove UPS 2nd Day Shipping rate if they are present in cart.
* Remove UPS 1-2 Day Ground for the rest of Continental U.S. Works for both WooThemes UPS Shipping and
* Syn Media UPS Shipping.
add_filter( 'woocommerce_package_rates', 'unset_ups_shipping_rates_for_specific_states' , 10, 2 );
function unset_ups_shipping_rates_for_specific_states( $rates, $package ) {
// Setup an array of states that do not allow UPS Shipping 2nd Day Air. As of 10/18/2015 we added 3 days ground too.
$excluded_states = array( 'FL','AL','KY','LA','MS','TN','GA','SC','NC','KY','DC','VA','AR','CT','DE','IL','IN','KS','MA','ME','MD','MN','MI','MO','NH','NJ','NY','OH','OK','PA','RI','TX','VT','WV','WI' );
if( in_array( WC()->customer->shipping_state, $excluded_states ) ) :
unset( $rates['sups:02:0'] ); // Unset 2-Day Air
unset( $rates['ups:02'] );
unset( $rates['sups:12:0'] ); // Unset 3-Day Select too
unset( $rates['ups:12'] );
unset( $rates['sups:03:0'] ); // Unset Ground
unset( $rates['ups:03'] );
// Return what's left of the $rates array
return $rates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment