Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 20, 2019 14:12
Show Gist options
  • Save xadapter/2db2a904b2ba5b0fcf533345c86d67f3 to your computer and use it in GitHub Desktop.
Save xadapter/2db2a904b2ba5b0fcf533345c86d67f3 to your computer and use it in GitHub Desktop.
Snippet to Hide WooCommerce Shipping method. Useful in case of Local Pickup plus. In case of Local pickup plus add a flat rate or free shipping in every zone, and hide it using below snippet. UPS or Fedex rate will get displayed. PluginHive Plugins - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/, https://ww…
/**
* Snippet to hide shipping method. Useful in case of Local Pickup plus. In case of Local pickup plus add a flat rate or free shipping in every zone, and hide it using below snippet. UPS or Fedex rate will get displayed.
* Created at : 04 July 2018
* Updated at : 04 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/2db2a904b2ba5b0fcf533345c86d67f3
*/
add_filter( 'woocommerce_package_rates',function( $shipping_rates ){
$shipping_methods_to_unset = array( 'flat_rate:6' ); // Shipping method id
foreach( $shipping_rates as $key => $shipping_rate ) {
$method_id = $shipping_rate->get_id();
if( in_array( $method_id, $shipping_methods_to_unset) ) {
unset($shipping_rates[$key]);
}
}
return $shipping_rates;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment