Last active
April 18, 2022 20:34
-
-
Save mlbd/d3f716f5f50efcb982c08e5d5701a275 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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 allaround_hide_shipping_when_free_is_available( $rates ) { | |
// Here your free shipping rate Id | |
$free_shipping_rate_id = 'free_shipping:6'; | |
// When your Free shipping method is available | |
if ( array_key_exists( $free_shipping_rate_id, $rates ) ) { | |
// Loop through shipping methods rates | |
foreach ( $rates as $rate_key => $rate ) { | |
// Removing "Flat rate" shipping method | |
if ( 'flat_rate' === $rate->method_id ){ | |
unset($rates[$rate_key]); | |
} | |
} | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'allaround_hide_shipping_when_free_is_available', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment