Display the product sale price in the checkout in WooCommerce

Display the product sale price in the checkout in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'woocommerce_cart_item_subtotal', 'show_sale_price_at_checkout', 10, 3 );
function show_sale_price_at_checkout( $subtotal, $cart_item, $cart_item_key ) {
    
    // gets the product object
    $product = $cart_item['data'];
    // get the quantity of the product in the cart
    $quantity = $cart_item['quantity'];

    // check if the object exists
    if ( ! $product ) {
        return $subtotal;
    }

    // check if the product is on sale
    if ( $product->is_on_sale() && ! empty( $product->get_sale_price() ) ) {
        // shows sale price and regular price       
        $price = wc_format_sale_price (
            // regular price
            wc_get_price_to_display(
                $product, array(
                    'price' => $product->get_regular_price(),
                    'qty' => $quantity
                    )
                ),
            // sale price
            wc_get_price_to_display( $product, array (
                'price' => $product->get_sale_price(),
                'qty' => $quantity
                )
            )
        ) . $product->get_price_suffix();
    } else {
        // shows regular price
        $price = wc_price (
            // regular price
            wc_get_price_to_display(
                $product, array (
                    'price' => $product->get_regular_price(),
                    'qty' => $quantity
                )
            )
        ) . $product->get_price_suffix();
    }
   
    return $price;
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.