Show Total Discount in WooCommerce Cart & Checkout

Code Snippets Coding Blog Custom Code Snippets PHP PHP Development Plugins Theme Optimization Woocommerce WooCommerce Customization WooCommerce Development Woocommerce Hooks WooCommerce Tips Wordpress WordPress Development

Show Total Discount in WooCommerce Cart & Checkout Tutorial/Guide

To show customers the total discount applied to their order in the WooCommerce cart and checkout, you can use the woocommerce_cart_totals_before_order_total and woocommerce_review_order_before_order_total hooks. Step 1: Open your active theme’s functions.php file. Step 2: Add the following code:

// Display total savings in 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');

Step 3: Save and upload the file back to your server. Now, the cart and checkout tables will display a new row labeled "Total Discount" that reflects the applied discount amount. Make sure to style the output to match your theme, and change the 'your-text-domain' to your theme or plugin’s actual text domain.  

💡 Have a Coding Problem?

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