Last active
August 26, 2020 19:33
-
-
Save munts/11e12c2491ae4cd92a7585a9b4a4b174 to your computer and use it in GitHub Desktop.
Hide WooCommerce shipping options when free shipping is available. Ie. hide Flat Rate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100 ); | |
function 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course, this is primarily valid if the shipping options are Flat Rate and Free Shipping. If you offer standard 3-5 day delivery, Business 2-3 day, and Express Overnight, as well as Free Shipping (5+ days) then you probably don't want to hide all the options.