Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 12, 2020 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/6319b12bcca869f15310bf4ae1b91b35 to your computer and use it in GitHub Desktop.
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/
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