Created
September 17, 2019 07:35
-
-
Save forsvunnet/8783f123343ec5e2d2ab0b015cec86c3 to your computer and use it in GitHub Desktop.
Black list shipping classes for bring shipping rates
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 | |
| /** | |
| * Filter the bring shipping rates. | |
| */ | |
| add_filter('bring_shipping_rates', function( $rates ) { | |
| $shipping_classes = [ | |
| 'halvpall', | |
| 'pall', | |
| 'stein', | |
| 'uuni-shipping', | |
| ]; | |
| // Look for items with a shipping class that doesn not allow mail. | |
| $items = WC()->cart->get_cart(); | |
| foreach ( $items as $item ) { | |
| $shipping_class = $item['data']->get_shipping_class(); | |
| if ( in_array( $shipping_class, $shipping_classes ) ) { | |
| return []; | |
| } | |
| } | |
| return $rates; | |
| }, 999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment