Last active
March 12, 2020 10:37
-
-
Save xadapter/6319b12bcca869f15310bf4ae1b91b35 to your computer and use it in GitHub Desktop.
Snippet to hide WooCommerce shipping methods based on the cart total. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
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', '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( | |
'wf_shipping_ups:03' | |
); | |
$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] ); | |
} | |
}else{ | |
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