Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Hide all free shipping options when the given shipping class is in the cart
- * Code snippets should be added to the functions.php file of your child theme
- *
- * @return array
- */
- function hide_shipping_when_class_is_in_cart( $rates, $package ) {
- // shipping class IDs that need the method removed
- $shipping_classes = array('bulky-items');
- $if_exists = false;
- foreach( $package['contents'] as $key => $values ) {
- if( in_array( $values[ 'data' ]->get_shipping_class(), $shipping_classes ) )
- $if_exists = true;
- }
- if( $if_exists ) {
- foreach( $rates as $key => $option ) {
- if( $option->method_id == 'free_shipping' )
- unset( $rates[ $key ] );
- }
- }
- return $rates;
- }
- add_filter( 'woocommerce_package_rates', 'hide_shipping_when_class_is_in_cart', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement