Skip to content

Instantly share code, notes, and snippets.

@dangoodman
Created January 12, 2017 20:34
Show Gist options
  • Save dangoodman/22e3055f8a55c710aed6f496b7e87929 to your computer and use it in GitHub Desktop.
Save dangoodman/22e3055f8a55c710aed6f496b7e87929 to your computer and use it in GitHub Desktop.
Hide duplicate shipping options in Woocommerce
<?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