Last active
October 11, 2024 16:29
-
-
Save braddalton/3e84a93cf4e545624385ed3a6e339ff0 to your computer and use it in GitHub Desktop.
How To Use World Wide Shipping Method With Multiple Zones https://wpsites.net/wordpress-tutorials/how-to-use-world-wide-shipping-method-with-multiple-zones/
This file contains 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
add_filter('woocommerce_package_rates', 'wpsites_remove_flat_rate_methods_over_150', 10, 2); | |
function wpsites_remove_flat_rate_methods_over_150($rates, $package) { | |
$cart_total = WC()->cart->get_cart_contents_total(); | |
$threshold = 150; | |
// Define the shipping method IDs to remove if cart total exceeds $150 | |
$methods_to_remove = array( | |
'flat_rate:12', | |
'flat_rate:13', | |
'flat_rate:14' | |
); | |
// Check if the cart total exceeds the threshold | |
if ($cart_total > $threshold) { | |
// Loop through the rates and unset the ones to remove | |
foreach ($rates as $rate_id => $rate) { | |
if (in_array($rate_id, $methods_to_remove)) { | |
unset($rates[$rate_id]); | |
} | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment