Created
February 5, 2016 12:14
-
-
Save ricardovelero/d88da5df610fb333c2a1 to your computer and use it in GitHub Desktop.
Filter WooCommerce shipping methods depending of state in address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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'] ); | |
else: | |
unset( $rates['sups:03:0'] ); // Unset Ground | |
unset( $rates['ups:03'] ); | |
endif; | |
// 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