WooCommerce: Display Total Discount / Savings @ Cart & Checkout

To display the total discount or savings amount in the cart and checkout pages of WooCommerce, you can use the `woocommerce_cart_totals_before_order_total` and `woocommerce_review_order_before_order_total` hooks. Here’s an example of how you can achieve this:

Step 1: Open your theme’s `functions.php` file.

Step 2: Add the following code to the file:

 

// Function to display total discount
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 the file and upload it to your theme directory.

With these steps, the `display_total_discount()` function will be triggered before the order total is displayed on the cart and checkout pages. It retrieves the total discount amount using the `get_cart_discount_total()` method and formats it using `wc_price()`.

The total discount will be displayed as a separate row in the cart and checkout tables, showing the discount amount under the “Total Discount” label.

Please note that you may need to adjust the code and customize the CSS styles to match your theme’s design. Additionally, replace `’your-text-domain’` with your actual text domain for translation purposes if needed.

By displaying the total discount or savings, you provide transparency to your customers, allowing them to see the reduced amount and the benefits of any applied discounts. This can help enhance their shopping experience and encourage conversions.

Leave a Comment

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