# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shipping, free-shipping, quantity
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-free-shipping-by-item-count/

## Code

```php
$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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Free Shipping From a Number of Items" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
