I am using the following code to show the total savings amount in checkout page:
add_action( 'woocommerce_review_order_after_order_total', 'show_total_discount_cart_checkout', 1000 );
function show_total_discount_cart_checkout() {
$discount_total = 0; // Initializing
// Loop through cart items
foreach ( WC()->cart->get_cart() as $item ) {
$product = $item['data'];
if ( $product->is_on_sale() ) {
$regular_args = array( 'price' => $product->get_regular_price() );
if ( WC()->cart->display_prices_including_tax() ) {
$active_price = wc_get_price_including_tax( $product );
$regular_price = wc_get_price_including_tax( $product, $regular_args );
} else {
$active_price = wc_get_price_excluding_tax( $product );
$regular_price = wc_get_price_excluding_tax( $product, $regular_args );
}
$discount_total += ( $regular_price - $active_price ) * $item['quantity'];
}
}
if ( WC()->cart->display_prices_including_tax() ) {
$discount_total += WC()->cart->get_discount_tax();
}
$discount_total += WC()->cart->get_discount_total();
if ( $discount_total > 0 ) {
$text = __("SÄÄSTÖSI", "woocommerce");
printf( '<tr class="total-saved"><th>%s</th><td data-title="%s">-%s</td></tr>', $text, $text, wc_price($discount_total) );
}
}
I would like also to show taht total savings amount in cart page and in the generated order. It seems to be the order-details.php temmplate responsible for customer orders.
How to show the total savings amount in cart page and in the generated order?
New contributor
Ekaterina Virtanen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.