Display WooCommerce Savings on Cart and Checkout Pages

Advanced Guides Code Snippets Coding Blog PHP PHP Debugging PHP Snippets Plugins Woocommerce WooCommerce Custom Code Woocommerce Hooks WooCommerce Tips Wordpress WordPress Code Snippets WordPress Development WordPress Functions

Display WooCommerce Savings on Cart and Checkout Pages Tutorial/Guide

You can enhance your WooCommerce store by showing users the total discount they've received on both the cart and checkout pages. Use the following approach: Step 1: Open your theme's functions.php file or your custom plugin file. Step 2: Add this snippet:

// Show total discount in WooCommerce cart and checkout
function display_total_discount() {
    $total_discount = WC()->cart->get_cart_discount_total();

    if ($total_discount > 0) {
        $formatted_discount = wc_price($total_discount);
        echo '<tr class="total-discount"><th>' . __('Total Discount', 'your-text-domain') . '</th><td data-title="' . __('Total Discount', 'your-text-domain') . '">' . $formatted_discount . '</td></tr>';
    }
}
add_action('woocommerce_cart_totals_before_order_total', 'display_total_discount');
add_action('woocommerce_review_order_before_order_total', 'display_total_discount');

This function fetches the total discount using get_cart_discount_total() and displays it as a table row before the final order total. Make sure to use your actual text domain and tweak the styles if necessary to match your store’s look.  

💡 Have a Coding Problem?

Search our archives or reach out to our team for solutions and expert advice.