Skip to content

Instantly share code, notes, and snippets.

@raajtram
Forked from helgatheviking/free-item-shipping.php
Created April 13, 2017 14:59
Show Gist options
  • Save raajtram/1f4486547b573c8b1326dac6937d0d32 to your computer and use it in GitHub Desktop.
Save raajtram/1f4486547b573c8b1326dac6937d0d32 to your computer and use it in GitHub Desktop.
Remove certain items from shipping calculations
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