Free Shipping From a Number of Items
Unlocks the Free Shipping method once the cart holds a set number of items, for example six bottles or three books, instead of a money threshold.
Opens WPIDE on
Code
$wpide_free_ship_min_items = 6; // Items needed in the cart.
add_filter( 'woocommerce_shipping_free_shipping_is_available', function ( $available, $package ) use ( $wpide_free_ship_min_items ) {
if ( $available ) {
return $available;
}
$count = 0;
foreach ( (array) ( $package['contents'] ?? array() ) as $item ) {
$count += (int) $item['quantity'];
}
return $count >= $wpide_free_ship_min_items;
}, 20, 2 );
Notes
Each shipping zone needs a Free Shipping method, and that method's own minimum amount or coupon rule still applies if it is stricter.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.