Skip to content

Instantly share code, notes, and snippets.

@WooForce
Created May 18, 2016 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WooForce/b59e5c4ef16bad0ff23b71de31166f0c to your computer and use it in GitHub Desktop.
Save WooForce/b59e5c4ef16bad0ff23b71de31166f0c to your computer and use it in GitHub Desktop.
Hide methods based on destination zip code
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