Last active
May 12, 2017 18:32
-
-
Save adriandmitroca/d5f89422873c0093a431cf02e0cac752 to your computer and use it in GitHub Desktop.
WooCommerce - Hide shipping methods for specific shipping classes / Add support to hide shipping methods for specified shipping classes to WooCommerce
This file contains hidden or 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
| <?php | |
| add_filter('woocommerce_package_rates', 'hide_shipping_methods', 10, 2); | |
| /** | |
| * Hide specific shipping methods for packages with negative cost set. | |
| * There is no need to hard code any IDs of shipping classes or products if you can just set negative value | |
| * on the back-end and then delete these methods on the fly. | |
| * | |
| * @param $rates | |
| * @param $package | |
| * @return mixed | |
| * @version WooCommerce 3.0+ | |
| */ | |
| function hide_shipping_methods($rates, $package) { | |
| foreach ($package['rates'] as $key => $value) { | |
| if ((float)$value->cost < 0) { | |
| unset($rates[$key]); | |
| } | |
| } | |
| return $rates; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment