Skip to content

Instantly share code, notes, and snippets.

@themepaint
Last active March 30, 2016 16:57
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 themepaint/ca41b9fea3fb4f18a7e28c255adf9e12 to your computer and use it in GitHub Desktop.
Save themepaint/ca41b9fea3fb4f18a7e28c255adf9e12 to your computer and use it in GitHub Desktop.
Change Default shipping methode.
/**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
* @return array of modified rates
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
// Only modify rates if free_shipping is present
if ( isset( $rates['local_delivery '] ) ) {
// To unset a single rate/method, do the following. This example unsets flat_rate shipping
unset( $rates['flat_rate'] );
// To unset all methods except for free_shipping, do the following
$local_delivery = $rates['local_delivery'];
$rates = array();
$rates['local_delivery '] = $local_delivery ;
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment