Skip to content

Instantly share code, notes, and snippets.

@dangoodman
Created April 8, 2020 13:40
Show Gist options
  • Save dangoodman/0c8aba61b396fa1bcedf15fea8d04acd to your computer and use it in GitHub Desktop.
Save dangoodman/0c8aba61b396fa1bcedf15fea8d04acd to your computer and use it in GitHub Desktop.
WooCommerce: round up shipping prices
<?php
// Paste everything below this line to your child-theme's functions.php file.
// Rounds up all shipping rates by the $roundUpBy value.
// 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) {
$roundUpBy = 5;
foreach ($rates as $rate) {
$rate->cost = ceil($rate->cost / $roundUpBy) * $roundUpBy;
}
return $rates;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment