Last active
February 10, 2021 06:07
-
-
Save bublick/3a04e81792190c5f8abe277734ce670d to your computer and use it in GitHub Desktop.
Hide shipping rates when free shipping is available
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
/** | |
* WordPress + WooCommerce | |
* Hide shipping rates when free shipping is available | |
*/ | |
function lis_woo_show_free_shipping_only( $rates, $package ) { | |
$new_shipping_rates = array(); | |
foreach ( $rates as $rate_id => $rate ) { | |
// Fill new shipping rates array only if free shipping is available. | |
if ( 'free_shipping' === $rate->method_id ) { | |
$new_shipping_rates[ $rate_id ] = $rate; | |
break; | |
} | |
} | |
if ( ! empty( $new_shipping_rates ) ) { | |
return $new_shipping_rates; | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'lis_woo_show_free_shipping_only', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment