# Show the Total Weight in the Cart and Checkout

> Adds a "Total weight" row to the cart and checkout totals, useful for stores that charge shipping by weight.

- 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-cart-total-weight/

## Code

```php
$wpide_cart_weight_row = function () {
    if ( ! WC()->cart ) {
        return;
    }

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

    if ( $weight <= 0 ) {
        return;
    }

    printf(
        '<tr class="wpide-cart-weight"><th>%s</th><td data-title="%s">%s</td></tr>',
        esc_html( 'Total weight' ),
        esc_attr( 'Total weight' ),
        esc_html( wc_format_weight( $weight ) )
    );
};

add_action( 'woocommerce_cart_totals_before_order_total', $wpide_cart_weight_row );
add_action( 'woocommerce_review_order_before_order_total', $wpide_cart_weight_row );
```

## Notes

Uses the weight unit set in WooCommerce > Settings > Products.

## How to use it

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