# "You're Saving X" Summary Above the Cart

> Adds up the discounts from sale prices and coupons in the cart and shows the total saving at the top of the cart page.

- Type: PHP
- Runs: Woocommerce before cart
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, cart, sale, conversion
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-cart-savings-summary/

## Code

```php
if ( WC()->cart && ! WC()->cart->is_empty() ) {
    $saving = 0;

    foreach ( WC()->cart->get_cart() as $item ) {
        $product = $item['data'];

        if ( $product->is_on_sale() ) {
            $regular = (float) wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) );
            $current = (float) wc_get_price_to_display( $product );
            $saving += max( 0, $regular - $current ) * (int) $item['quantity'];
        }
    }

    $saving += (float) WC()->cart->get_discount_total() + ( WC()->cart->display_prices_including_tax() ? (float) WC()->cart->get_discount_tax() : 0 );

    if ( $saving > 0 ) {
        echo '<div class="wpide-cart-savings" style="margin:0 0 20px;padding:12px 16px;border-radius:6px;background:#edfaef;color:#1e4620;font-weight:600;">' . wp_kses_post( sprintf( 'You are saving %s on this order!', wc_price( $saving ) ) ) . '</div>';
    }
}
```

## Notes

Only appears when the shopper saves something. Sale savings use the regular price of each product.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""You're Saving X" Summary Above the Cart" 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/
