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.
Jamie managed to code a handy snippet to display inside Cart and Checkout totals the total amount of money a customer saved (sale prices plus coupon discounts). Over the years this snippet went through several revisions, but it’s still working smoothly – enjoy!
PHP Snippet: Show How Much Customer Saved @ WooCommerce Cart and Checkout Pages
/** * @snippet Display Total Discount @ WooCommerce Cart/Checkout * @how-to Get CustomizeWoo.com FREE * @author Rodolfo Melogli, BusinessBloomer.com * @testedwith WooCommerce 4.6 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ add_action( 'woocommerce_cart_totals_after_order_total' , 'bbloomer_show_total_discount_cart_checkout' , 9999 ); add_action( 'woocommerce_review_order_after_order_total' , 'bbloomer_show_total_discount_cart_checkout' , 9999 ); function bbloomer_show_total_discount_cart_checkout() { $discount_total = 0; foreach ( WC()->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>You Saved</th><td data-title="You Saved">' . wc_price( $discount_total + WC()->cart->get_discount_total() ) . '</td></tr>' ; } |
No comments:
Post a Comment