Display You Saved in Cart Totals

Display "You Saved" in cart totals.

add_filter( 'woocommerce_cart_totals_order_total_html', function($cart_total_price) {
    $discount_total = 0;

    // Calculate default discount price total
    foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
        $product = $values['data'];
        if ($product->is_on_sale()) {
            $regular_price = $product->get_regular_price();
            $sale_price = $product->get_sale_price();
            if(!empty($sale_price)){
                $discount = ($regular_price - $sale_price) * $values['quantity'];
                $discount_total += $discount;
            }
        }
    }

    // Add Woo Discount Rules discount price total
    if (class_exists('\Wdr\App\Router')) {
        $manage_discount = \Wdr\App\Router::$manage_discount;
        if (method_exists($manage_discount, 'getDiscountPerItem')) {
            if (!empty($manage_discount::$calculated_cart_item_discount)) {
                foreach ($manage_discount::$calculated_cart_item_discount as $discount_details) {
                    if (!empty($discount_details)) {
                        $discount_total += $manage_discount->getDiscountPerItem($discount_details);
                    }
                }
            }
        }
    }

    // Add Cart discount total
    $discount_total += WC()->cart->get_discount_total();


    if ($discount_total > 0) {
        $cart_total_price .= '<div class="awdr-you-saved-text" style="color: green">' . 'You Saved' .wc_price($discount_total). '</div>';
    }

    return $cart_total_price;
},10000,1);