showing sale prices in the woocommerce checkout

Solutions on MaxInterview for showing sale prices in the woocommerce checkout by the best coders in the world

showing results for - "showing sale prices in the woocommerce checkout"
Nora
04 Jun 2017
1
2function show_sale_price_at_checkout( $subtotal, $cart_item, $cart_item_key ) {
3    
4    $product = $cart_item['data'];
5    $quantity = $cart_item['quantity'];
6    if ( ! $product ) {
7        return $subtotal;
8    }
9    $regular_price = $sale_price = $suffix = '';
10    if ( $product->is_taxable() ) {
11        if ( 'excl' === WC()->cart->tax_display_cart ) {
12            $regular_price = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) );
13            $sale_price    = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_sale_price(), 'qty' => $quantity ) );
14            if ( WC()->cart->prices_include_tax && WC()->cart->tax_total > 0 ) {
15                $suffix .= ' ' . WC()->countries->ex_tax_or_vat() . '';
16            }
17        } else {
18            $regular_price = wc_get_price_including_tax( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) );
19            $sale_price = wc_get_price_including_tax( $product, array( 'price' => $product->get_sale_price(), 'qty' => $quantity ) );
20            if ( ! WC()->cart->prices_include_tax && WC()->cart->tax_total > 0 ) {
21                $suffix .= ' ' . WC()->countries->inc_tax_or_vat() . '';
22            }
23        }
24    } else {
25        $regular_price    = $product->get_price() * $quantity;
26        $sale_price       = $product->get_sale_price() * $quantity;
27    }
28    if ( $product->is_on_sale() && ! empty( $sale_price ) ) {
29        $price = wc_format_sale_price(
30                     wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price(), 'qty' => $quantity ) ),
31                     wc_get_price_to_display( $product, array( 'qty' => $quantity ) )
32                 ) . $product->get_price_suffix();
33    } else {
34        $price = wc_price( $regular_price ) . $product->get_price_suffix();
35    }
36   
37    $price = $price . $suffix;
38    return $price;
39}
40add_filter( 'woocommerce_cart_item_subtotal', 'show_sale_price_at_checkout', 10, 3 );
41
similar questions