If you love Ecommerce as much as I do, and are passionate about Sales Conversion Rate and reducing Shopping Cart Abandonment, today’s snippet will come in handy.

Besides, this is officially the first guest blog on Business Bloomer (have ideas? Send me your proposal here)… so let me officially introduce you to today’s author: Jamie Gill, a WordPress & WooCommerce enthusiast from Bradford, UK.

WooCommerce: Show Total Savings / Total Discount Amount @ Cart & Checkout Pages
WooCommerce: Show Total Savings / Total Discount Amount @ Cart & Checkout Pages WooCommerce: Show Total Savings / Total Discount Amount @ Cart & Checkout Pages

WooCommerce PHP Snippet: Display Total Discount Amount / Total Savings @ Cart & Checkout


/**
* @snippet Display Total Discount / Savings @ WooCommerce Cart/Checkout
* @how-to Get CustomizeWoo.com FREE
* @sourcecode https://businessbloomer.com/?p=20362
* @author Rodolfo Melogli, Bülent Sakarya
* @testedwith WooCommerce 3.0
*/

function bbloomer_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 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', 'bbloomer_wc_discount_total_30', 99);
add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_wc_discount_total_30', 99);

Share:

Leave a Reply