Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simonlk/4152419 to your computer and use it in GitHub Desktop.
Save simonlk/4152419 to your computer and use it in GitHub Desktop.
Woocommerce - hide other shipping methods when free shipping is available
// Based on http://wcdocs.woothemes.com/snippets/hide-other-shipping-methods-when-free-shipping-is-available/
// Goes beyond by hiding the default internation shipping too
// Hide shipping options when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) AND (isset( $available_methods['flat_rate'] ) || (isset( $available_methods['international_delivery']) ))) {
// remove standard shipping option
unset( $available_methods['flat_rate'] );
// Remove international delivery
unset( $available_methods['international_delivery']);
}
return $available_methods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment