-
-
Save raajtram/1f4486547b573c8b1326dac6937d0d32 to your computer and use it in GitHub Desktop.
Remove certain items from shipping calculations
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
function remove_free_shipping_items( $packages ) { | |
foreach( $packages as $i => $package ){ | |
foreach ( $package['contents'] as $key => $item ) { | |
if ( $item['data']->get_shipping_class() == 'free' ) { | |
unset( $packages[$i]['contents'][$key] ); | |
add_filter( 'woocommerce_cart_needs_shipping', '__return_true' ); | |
} | |
} | |
} | |
return $packages; | |
} | |
add_filter( 'woocommerce_cart_shipping_packages', 'remove_free_shipping_items' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment