WooCommerce Display Total Discount @ 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.

[TheChamp-Sharing]

Related Blogs

WooCommerce: Display Regular & Sale Price @ Cart Table

Learn how to enhance your WooCommerce cart table by displaying both the regular and sale prices. Implement this functionality using WordPress hooks and filters to provide clear and appealing pricing information to your customers, encouraging sales and improving the shopping experience.

Disable plugin update in WordPress

While it’s generally not recommended to disable plugin updates in WordPress due to security and functionality improvements, there might be specific cases where you need to prevent certain plugins from updating. Keep in mind that doing so may leave your site vulnerable to security issues and may cause compatibility problems with future WordPress versions.

Request A Quote

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.