Created
May 19, 2021 12:33
-
-
Save dangoodman/6b27ee87783d8736f1f8dde1a132785c to your computer and use it in GitHub Desktop.
"Squash" all delivery options into a single one
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
<?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