+91 9737971210
info@wordpressdeveloperonline.com
Facebook
Facebook
Twitter
Twitter
Google+
Google+
LinkedIn
LinkedIn
Instagram
Instagram
WORDPRESS DEVELOPER
Menu
  • HOME
  • SERVICES
    • Free WordPress Setup
      • Free WordPress Website Blog
    • Hire WordPress Developer
      • WordPress Emergency Support
      • Hire PHP Developer
      • Hire WooCommerce Developer
      • Woocommerce Customization
      • Fix WordPress Errors
      • Fix WordPress Security
      • Multi Language Website Blog with WPML
    • Online Shopping Website
    • WordPress Theme Development
      • Avada Theme Experts
      • Divi Expert Services
      • Enfold Theme Expert
      • Jupiter Theme Expert
      • X Theme Expert Services
      • NewsPaper Theme Experts Services
    • PSD to WordPress
    • Speed Performance Optimization
    • WordPress Hosting Migration
    • SEO Link Building
  • PACKAGES
    • Speed Optimization Packages
  • WHY WE
    • PORTFOLIO
    • TESTIMONIALS
    • CAREER
  • BLOG
  • CONTACT

Showing Sale Prices in the WooCommerce Checkout

September 20, 2018wordpressdeveloperWoocommerce

By default WooCommerce displays regular price (Provided there is no sale price available) or Sale Price with striked regular price on Shop and Single Product pages.

But if you would like to Display Regular/Sale Price in the Woocommerce chekout. here is a simple method to achieve this. Let’s see.

Add below line of code at the end of your theme’s functions.php file of your active child theme (or theme) and Save the file.


function show_sale_price_at_checkout( $subtotal, $cart_item, $cart_item_key ) {
    
    $product = $cart_item['data'];
    $quantity = $cart_item['quantity'];
    if ( ! $product ) {
        return $subtotal;
    }
    $regular_price = $sale_price = $suffix = '';
    if ( $product->is_taxable() ) {
        if ( 'excl' === WC()->cart->tax_display_cart ) {
            $regular_price = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) );
            $sale_price    = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_sale_price(), 'qty' => $quantity ) );
            if ( WC()->cart->prices_include_tax && WC()->cart->tax_total > 0 ) {
                $suffix .= ' ' . WC()->countries->ex_tax_or_vat() . '';
            }
        } else {
            $regular_price = wc_get_price_including_tax( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) );
            $sale_price = wc_get_price_including_tax( $product, array( 'price' => $product->get_sale_price(), 'qty' => $quantity ) );
            if ( ! WC()->cart->prices_include_tax && WC()->cart->tax_total > 0 ) {
                $suffix .= ' ' . WC()->countries->inc_tax_or_vat() . '';
            }
        }
    } else {
        $regular_price    = $product->get_price() * $quantity;
        $sale_price       = $product->get_sale_price() * $quantity;
    }
    if ( $product->is_on_sale() && ! empty( $sale_price ) ) {
        $price = wc_format_sale_price(
                     wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) ),
                     wc_get_price_to_display( $product, array( 'qty' => $quantity ) )
                 ) . $product->get_price_suffix();
    } else {
        $price = wc_price( $regular_price ) . $product->get_price_suffix();
    }
   
    $price = $price . $suffix;
    return $price;
}
add_filter( 'woocommerce_cart_item_subtotal', 'show_sale_price_at_checkout', 10, 3 );