Display WooCommerce Savings on Cart and Checkout Pages

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.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.