Display product discount in order review
-
I am currently using this code to display the total amount saved (regular price minus the sale price) and it works fine:
<?php function wc_discount_total_30() { global $woocommerce; $discount_total = 0; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if ( $_product->is_on_sale() ) { $regular_price = $_product->get_regular_price(); $sale_price = $_product->get_sale_price(); $discount = ($regular_price - $sale_price) * $values['quantity']; $discount_total += $discount; } } if ( $discount_total > 0 ) { echo '<tr> <th class="rabatt_tittel">Total savings</th> <td class="rabatt_sum">-' . wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td> </tr>'; } } add_action( 'woocommerce_review_order_before_order_total', 'wc_discount_total_30' , 50);
`
However, if someone uses a coupon for let’s say $10, that $10 is added to the total discount which is technically correct behaviour.
What I want to achieve is to have that code above display the sale discount only, as the coupon discount is added on a seperate line and I want to have them separated.
How can I achieve this?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Display product discount in order review’ is closed to new replies.