# Maximum Cart Weight

> Prevents checkout when the products in the cart weigh more than your carrier allows and tells the customer by how much they are over.

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

## Code

```php
add_action( 'woocommerce_check_cart_items', function () {
    $max_weight = 30; // In the store weight unit (kg, lbs...).

    $weight = (float) WC()->cart->get_cart_contents_weight();

    if ( $weight > $max_weight ) {
        wc_add_notice( sprintf( 'Your order weighs %1$s, above our maximum of %2$s per order. Please remove %3$s to continue.', wc_format_weight( $weight ), wc_format_weight( $max_weight ), wc_format_weight( $weight - $max_weight ) ), 'error' );
    }
} );
```

## Notes

Set $max_weight in your store's weight unit. Products without a weight count as 0.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Maximum Cart Weight" 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/
