Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Last active April 30, 2019 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ChromeOrange/6063973 to your computer and use it in GitHub Desktop.
Save ChromeOrange/6063973 to your computer and use it in GitHub Desktop.
Remove all shipping options except Free Shipping if Free Shipping is available.
// Hide ALL shipping options when free shipping is available
add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 1 );
/**
* Hide ALL Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_all_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) ) :
foreach ( $available_methods as $available_method ) {
$available_method = get_object_vars( $available_method );
if ( $available_method['id'] != 'free_shipping' ) :
unset( $available_methods[$available_method['id']] );
endif;
}
endif;
return $available_methods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment