Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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' );

This comment has been minimized.

Copy link

surfzen commented Sep 6, 2017

This is great, thanks! One issue I see is that if the user only buys the free shipping items, they get the "There are no shipping methods available." notice, which is not ideal. I want to preserve that notice if there is actually a shipping problem (bad postal code, out of area, etc), but otherwise have something like "No charge for shipping on this item!" Is that easy enough to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.