Skip to content

Instantly share code, notes, and snippets.

@WooForce
Created August 17, 2016 06:27
Show Gist options
  • Save WooForce/0111b0bc06ec2ed7d8a651f3dcfd1e84 to your computer and use it in GitHub Desktop.
Save WooForce/0111b0bc06ec2ed7d8a651f3dcfd1e84 to your computer and use it in GitHub Desktop.
Hide Shipping methods when free shipping is available
add_filter('woocommerce_package_rates', 'wf_hide_shipping_methods_when_free_shipping_is_applicable', 10, 2);
function wf_hide_shipping_methods_when_free_shipping_is_applicable($rates, $package)
{
foreach($rates as $key => $value) {
if (strpos($key , 'free_shipping') !== false) {
foreach($rates as $ratekey => $ratevalue) {
if (strpos($ratekey, 'free_shipping') !== false) {
continue;
}
unset($rates[$ratekey]);
}
}
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment