0
(0)
Use the following code Snippet to display savings in woocommerce cart page.
PHP Code
function code_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 product values to the cart and Checkout pages
add_action( 'woocommerce_cart_totals_after_order_total', 'code_wc_discount_total', 99);
add_action( 'woocommerce_review_order_after_order_total', 'code_wc_discount_total', 99);
How useful was this post?
Click on a star to rate it!
Average rating 0 / 5. Vote count: 0
No votes so far! Be the first to rate this post.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
Total Views:
84
Share