Created
October 11, 2024 08:49
-
-
Save braddalton/0bdfb3e02a69d707962a8e8e63679c66 to your computer and use it in GitHub Desktop.
Show Hide Shipping Methods Based on Cart Totals in WooCommerce https://wpsites.net/wordpress-tutorials/show-hide-shipping-methods-based-on-cart-totals-in-woocommerce/
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', '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