-
-
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/
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
/** | |
* 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