Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Created September 27, 2016 09:29
Show Gist options
  • Save SiR-DanieL/c39f8c3498e6cec810986669c43723b8 to your computer and use it in GitHub Desktop.
Save SiR-DanieL/c39f8c3498e6cec810986669c43723b8 to your computer and use it in GitHub Desktop.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
@Yizi
Copy link

Yizi commented Mar 6, 2018

Any ideas how we can add a clause to show another shipping method along the way e.g. Special Delivery. So if the customer is eligible for the FREE shipping they will also see the option for Special Delivery just in case they need it faster...

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