Skip to content

Instantly share code, notes, and snippets.

@dariodev
Forked from dangoodman/functions.php
Created November 23, 2020 22:20
Show Gist options
  • Save dariodev/ec4a337abd98ce174c67e652f304b528 to your computer and use it in GitHub Desktop.
Save dariodev/ec4a337abd98ce174c67e652f304b528 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