Created
November 3, 2023 14:18
-
-
Save reandimo/975d8487629441e16952d92751b47edb to your computer and use it in GitHub Desktop.
Hide shipping rates when free shipping is available in Woocommerce's Checkout
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
<?php | |
add_filter('woocommerce_package_rates', 'maybe_force_free_shipping', 99); | |
/** | |
* @param array $rates Array of rates found for the package. | |
* @return array | |
*/ | |
function maybe_force_free_shipping($rates) | |
{ | |
$free = array(); | |
foreach ($rates as $rate_id => $rate) { | |
if ($rate->method_id == 'free_shipping') { | |
$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