Skip to content

Instantly share code, notes, and snippets.

@WooForce
Last active March 31, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WooForce/c8558f8157c541bd5c51 to your computer and use it in GitHub Desktop.
Save WooForce/c8558f8157c541bd5c51 to your computer and use it in GitHub Desktop.
WooCommerce: Hide the undesired service for the required states
add_filter('woocommerce_package_rates', 'wf_hide_undesired_service_for_required_states', 10, 2);
function wf_hide_undesired_service_for_required_states($rates, $package)
{
$exclude = array(
'international_delivery' => array(
'CA'
) ,
'wf_fedex_woocommerce_shipping:FEDEX_GROUND' => array(
'FL'
)
);
if (is_array($exclude)) {
foreach($exclude as $shipping_method => $excluded_states) {
if (in_array(WC()->customer->shipping_state, $excluded_states)) {
unset($rates[$shipping_method]);
}
}
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment