Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created October 11, 2024 08:49
Show Gist options
  • Save braddalton/0bdfb3e02a69d707962a8e8e63679c66 to your computer and use it in GitHub Desktop.
Save braddalton/0bdfb3e02a69d707962a8e8e63679c66 to your computer and use it in GitHub Desktop.
add_filter('woocommerce_package_rates', 'switch_flat_rate_based_on_total_v3', 10, 2);
function switch_flat_rate_based_on_total_v3($rates, $package) {
$cart_total = WC()->cart->get_cart_contents_total();
$flat_rate_5 = 'flat_rate:5'; // ID for flat rate 5
$flat_rate_7 = 'flat_rate:7'; // ID for flat rate 7
if ($cart_total > 150) {
if (isset($rates[$flat_rate_5])) {
unset($rates[$flat_rate_5]);
}
} else {
if (isset($rates[$flat_rate_7])) {
unset($rates[$flat_rate_7]);
}
}
return $rates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment