Created
January 12, 2017 20:34
-
-
Save dangoodman/22e3055f8a55c710aed6f496b7e87929 to your computer and use it in GitHub Desktop.
Hide duplicate shipping options in Woocommerce
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 | |
// Paste everything below this line to your theme's functions.php file. | |
add_filter('woocommerce_package_rates', function($rates) { | |
/** @var WC_Shipping_Rate[] $rates */ | |
/** @var WC_Shipping_Rate[] $uniqueRates */ | |
$uniqueRates = array(); | |
foreach ($rates as $key => $rate) { | |
$unique = true; | |
foreach ($uniqueRates as $uniqueRate) { | |
if ($uniqueRate->get_label() == $rate->get_label() && $uniqueRate->cost == $rate->cost) { | |
$unique = false; | |
break; | |
} | |
} | |
if ($unique) { | |
$uniqueRates[$key] = $rate; | |
} | |
} | |
return $uniqueRates; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment