Display discounted sub-total after coupon.

/** * Show the product price before (striked out) and after coupon discount * @uses wpq_9522_discount() * @link http://www.wpquestions.com/question/showChronoLoggedIn/id/9522 */ function wpq_9522_woocommerce_cart_item_subtotal( $subtotal, $cart_item, $cart_item_key ){ foreach ( WC()->cart->get_coupons( 'order' ) as $code => $coupon ) : if( in_array( $cart_item['product_id'], $coupon->product_ids ) || in_array( $coupon->discount_type, array( 'percent_cart', 'fixed_cart' ) ) ): $newsubtotal = wc_price( wpq_9522_discount( $cart_item['line_total'], $coupon->discount_type, $coupon->amount ) ); return sprintf( '<s>%s</s> %s', $subtotal, $newsubtotal ); endif; endforeach; return $subtotal; } add_filter( 'woocommerce_cart_item_subtotal', 'wpq_9522_woocommerce_cart_item_subtotal', 99, 3 ); /** * Show the cart subtotal before (striked out) and after coupon discount * @uses wpq_9522_discount() * @link http://www.wpquestions.com/question/showChronoLoggedIn/id/9522 */ function wpq_9522_woocommerce_cart_subtotal( $cart_subtotal, $compound, $obj ){ $t = 0; foreach ( $obj->cart_contents as $key => $product ) : $product_price = $product['line_total']; foreach ( WC()->cart->get_coupons( 'order' ) as $code => $coupon ) : if( in_array( $product['product_id'], $coupon->product_ids ) || in_array( $coupon->discount_type, array( 'percent_cart', 'fixed_cart' ) ) ): $product_price = wpq_9522_discount( $product['line_total'], $coupon->discount_type, $coupon->amount ); endif; endforeach; $t += $product_price; endforeach; return ( $t > 0 ) ? sprintf( '<s>%s</s> %s', $cart_subtotal, wc_price( $t ) ) : $cart_subtotal ; } add_filter( 'woocommerce_cart_subtotal', 'wpq_9522_woocommerce_cart_subtotal', 99, 3 );
Credit to: http://www.wpquestions.com/question/showChronoLoggedIn/id/9522.

This function will put a strike through the sub-total and display the price after coupon, but before shipping.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.