Last active
July 8, 2019 14:28
-
-
Save imran-khan1/b5932f9ba6180082df444d93c2a52897 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ik_wc_discount_total() { | |
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 class="cart-discount"> | |
<th>'. __( 'You Saved', 'woocommerce' ) .'</th> | |
<td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">' | |
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td> | |
</tr>'; | |
} | |
} | |
// Hook our values to the Basket and Checkout pages | |
add_action( 'woocommerce_cart_totals_after_order_total', 'ik_wc_discount_total', 90); | |
add_action( 'woocommerce_review_order_after_order_total', 'ik_wc_discount_total', 90); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment