Created
May 18, 2016 14:25
-
-
Save WooForce/b59e5c4ef16bad0ff23b71de31166f0c to your computer and use it in GitHub Desktop.
Hide methods based on destination zip code
This file contains hidden or 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
add_filter('woocommerce_package_rates', 'wf_hide_shipping_methods_based_on_zipcode', 10, 2); | |
function wf_hide_shipping_methods_based_on_zipcode($available_shipping_methods, $package){ | |
$destination = $package['destination']; | |
$postcode = $destination['postcode']; | |
// Array of zipcodes with shipping methods to hide | |
$hide_methods = array( | |
'90002' => array( | |
'free_shipping', | |
'wf_shipping_usps:D_PRIORITY_MAIL', | |
), | |
'90003' => array( | |
'flat_rate', | |
), | |
'90007' => array( | |
'free_shipping', | |
), | |
); | |
if(key_exists($postcode, $hide_methods)){ | |
$shipping_services_to_hide = $hide_methods[$postcode]; | |
foreach($shipping_services_to_hide as & $value) { | |
unset($available_shipping_methods[$value]); | |
} | |
} | |
return $available_shipping_methods; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment