Skip to content

Instantly share code, notes, and snippets.

@boywondercreative
Forked from varun-pluginhive/functions.php
Created March 13, 2019 22:42
Show Gist options
  • Save boywondercreative/0f529e145adc2c8c794aafe89937809f to your computer and use it in GitHub Desktop.
Save boywondercreative/0f529e145adc2c8c794aafe89937809f to your computer and use it in GitHub Desktop.
Snippet to hide specified shipping methods with zero cost. PluginHive Plugins : https://www.pluginhive.com/plugins/
/**
* Snippet to hide specified shipping methods with zero cost.
* Created at : 07 Nov 2018
* Updated at : 07 Nov 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/varun-pluginhive/a7b88d265b5ecb89d823ffe9d06daf7c
*/
add_filter( 'woocommerce_package_rates', function( $shipping_rates ){
$shipping_methods = array( 'wf_woocommerce_shipping_pro:1shipping-pro-1'); // Array of Shipping method ids
foreach( $shipping_rates as $key => $shipping_rate ){
if( in_array( $shipping_rate->get_id(), $shipping_methods ) ) {
$shipping_cost = (double) $shipping_rate->get_cost();
if( empty($shipping_cost) )
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