Skip to content

Instantly share code, notes, and snippets.

@dangoodman
Created May 19, 2021 12:33
Show Gist options
  • Save dangoodman/6b27ee87783d8736f1f8dde1a132785c to your computer and use it in GitHub Desktop.
Save dangoodman/6b27ee87783d8736f1f8dde1a132785c to your computer and use it in GitHub Desktop.
"Squash" all delivery options into a single one
<?php
// Paste everything below this line to your child-theme's functions.php file.
// "Squashes" all delivery options into a single one.
// After pasting this snippet, reset the WooCommerce shipping cache, e.g. add an item to the cart.
add_filter('woocommerce_package_rates', function ($rates, $package) {
if (count($rates) > 1) {
$firstRate = null;
$firstRateId = null;
foreach ($rates as $id => $rate) {
if (!isset($firstRate)) {
$firstRate = $rate;
$firstRateId = $id;
} else {
$firstRate->cost += $rate->cost;
}
}
$rates = [$firstRateId => $firstRate];
}
return $rates;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment