Title: Snippet Exclude Code not working
Last modified: August 31, 2016

---

# Snippet Exclude Code not working

 *  [JakesWheel](https://wordpress.org/support/users/jakeswheel/)
 * (@jakeswheel)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/snippet-exclude-code-not-working/)
 * I am not able to get the Snippet Code to work. I want to run a code to exclude
   FedEx Ground shipping to all customers living outside of a 2 day delivery area.
   This is the code I used, that does not work. Any suggestions?
    add_filter( ‘woocommerce_package_rates’,‘
   wf_remove_shipping_pro_rate_when_free_shipping_is_applicable’, 10, 2 );
 * function wf_remove_shipping_pro_rate_when_free_shipping_is_applicable( $rates,
   $package )
    {
 *  $exclude = array(
    ‘wf_fedex_woocommerce_shipping:FEDEX_GROUND’=>array(‘AK’,’
   AZ’,’CA’,’CO’,’CT’,’DE’,’FL’,’GA’,’HI’,’ID’,’ME’,’MD’,’MA’,’MT’,’NE’,’NV’,’NH’,’
   NM’,’ND’,’OK’,’OR’,’RI’,’SD’,’TX’,’UT’,’VT’,’VA’,’WA’,’WY’)); $exclude = array(‘
   wf_fedex_woocommerce_shipping:FEDEX_GROUND_HOME_DELIVERY’=>array(‘AK’,’AZ’,’CA’,’
   CO’,’CT’,’DE’,’FL’,’GA’,’HI’,’ID’,’ME’,’MD’,’MA’,’MT’,’NE’,’NV’,’NH’,’NM’,’ND’,’
   OK’,’OR’,’RI’,’SD’,’TX’,’UT’,’VT’,’VA’,’WA’,’WY’));
 * 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;
    }
 * [https://wordpress.org/plugins/code-snippets/](https://wordpress.org/plugins/code-snippets/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/snippet-exclude-code-not-working/#post-6917453)
 * Sorry, but I don’t work with WooCommerce myself, and I’m not really able to help
   with coding advice which is not directly related to the plugin.
 * I recommend asking this question in the WooCommerce support forums instead, where
   you should be able to receive much better help.

Viewing 1 replies (of 1 total)

The topic ‘Snippet Exclude Code not working’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [snippet code](https://wordpress.org/support/topic-tag/snippet-code/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/snippet-exclude-code-not-working/#post-6917453)
 * Status: not a support question