Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Hide shipping method(s) based on cart total.
add_filter('woocommerce_package_rates', 'wf_remove_shipping_options_basedon_cart_total', 10, 2);
function wf_remove_shipping_options_basedon_cart_total($rates, $package){
global $woocommerce;
$order_total_limit = 100; //Set here limit of cart total
$method_to_hide_when_cross_limit = array(
$method_to_show_when_cross_limit = array(
'free_shipping:1', //config here excat freeshipping key of you cart
$cart_total = WC()->cart->cart_contents_total;
if ( $cart_total >= $order_total_limit ) {
foreach ($method_to_hide_when_cross_limit as $shipping_method) {
unset( $rates[$shipping_method] );
foreach ($method_to_show_when_cross_limit as $shipping_method) {
unset( $rates[$shipping_method] );
return $rates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.