Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Last active December 16, 2015 09:59
Show Gist options
  • Save ChromeOrange/5416643 to your computer and use it in GitHub Desktop.
Save ChromeOrange/5416643 to your computer and use it in GitHub Desktop.
Hide free shipping if shipping state for WooCommerce 2
add_filter( 'woocommerce_package_rates', 'hide_standard_shipping_in_state' , 10, 2 );
/**
* Hide free shipping if shipping state is AK, AL, AR, HI, MA, MS, PA, or UT
*
* @param array $available_methods
*/
function hide_standard_shipping_in_state( $rates, $package ) {
$excluded_states = array( 'AK','AL','AR','HI','MA','MS','PA','UT' );
if( isset( $rates['free_shipping'] ) AND in_array( WC()->customer->get_shipping_state(), $excluded_states ) ) {
// remove free shipping option
unset( $rates['free_shipping'] );
}
return $rates;
}
@bahbond
Copy link

bahbond commented Nov 30, 2015

Where would one put this snippet of code? I don't see any cart/checkout php. I apologize for my Newbness.

@bahbond
Copy link

bahbond commented Nov 30, 2015

Let me elaborate, I used this code during a pretty stressful time, and can't remember where I put it! It is currently working, but can't find it anywhere? I am using the storefront theme.. Thanks!

@ChromeOrange
Copy link
Author

@bahbond that code need to go in your theme functions.php file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment