0
votes

Iv setup my Woocommerce Site such that the prices are entered excluding tax.

However id like to show Prices Inclusive of tax on the cart and Product Pages but excluding on the Checkout Page.

The Issue is, Woocommerce by default allows you to select Includes/Excludes tax For Cart & Checkout Together. but I need them to display individually.

Any ideas?

1

1 Answers

1
votes

Use the filter woocommerce_get_price_including_tax on the single product pages. I copied the code out of the function get_price_including_tax. I haven't tested this code but this is the basic idea of what you need to do.

    function modify_woocommerce_get_price_including_tax( $price, $qty, $product ) {

    if( ! is_checkout() ) {
        $tax_rates      = WC_Tax::get_rates( $product->get_tax_class() );
        $base_tax_rates = WC_Tax::get_base_tax_rates( $product->tax_class );

        if ( ! empty( WC()->customer ) && WC()->customer->is_vat_exempt() ) {

            $base_taxes         = WC_Tax::calc_tax( $price * $qty, $base_tax_rates, true );
            $base_tax_amount    = array_sum( $base_taxes );
            $price              = round( $price * $qty - $base_tax_amount, wc_get_price_decimals() );

        /**
         * The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations.
         * e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.
         * product feature is experimental @since 2.4.7 and may change in the future. Use at your risk.
         */
        } elseif ( $tax_rates !== $base_tax_rates && apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ) {

            $base_taxes         = WC_Tax::calc_tax( $price * $qty, $base_tax_rates, true );
            $modded_taxes       = WC_Tax::calc_tax( ( $price * $qty ) - array_sum( $base_taxes ), $tax_rates, false );
            $price              = round( ( $price * $qty ) - array_sum( $base_taxes ) + array_sum( $modded_taxes ), wc_get_price_decimals() );

        } else {

            $price = $price * $qty;

        }
    }

    return $price;

}

add_filter( 'woocommerce_get_price_including_tax', 'modify_woocommerce_get_price_including_tax', 10, 3 );

If you want to modify the prices on the cart page then you'll need to override the template cart-totals.php in your child theme.