1
votes

I have one little isusue that dont know how to resolve myself. I have set in my shop to show separated Price and shipping costs but in total showed me bad price.

For example my products cost 24.99€ + SHIPPING FEE : 3,95€ = 28.94€ but in calculation in cart page is calculating: 24.99€ + 3.95€ - 0.26€ what is wrong.

enter image description here

i found that Total price is calculated via this function:

<td data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"><?php wc_cart_totals_order_total_html(); ?></td>

and this is function that control that part: from cart-totals.php in templates, and bellow is function from wc-cart-functions.php

function wc_cart_totals_order_total_html() {
$value = '<strong>' . WC()->cart->get_total() . '</strong> ';

// If prices are tax inclusive, show taxes here.
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
    $tax_string_array = array();
    $cart_tax_totals  = WC()->cart->get_tax_totals();

    if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) {
        foreach ( $cart_tax_totals as $code => $tax ) {
            $tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
        }
    } elseif ( ! empty( $cart_tax_totals ) ) {
        $tax_string_array[] = sprintf( '%s %s', wc_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
    }

    if ( ! empty( $tax_string_array ) ) {
        $taxable_address = WC()->customer->get_taxable_address();
        $estimated_text  = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
            ? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
            : '';
        $value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
    }
}

echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value );
}

So my question is how to add that 1.63E at Total Price, so will get correct price. Thanks

EDIT: Found the same problem like mine here but answers dont seems to make changes.

1
This piece of code alone may not be enough. Maybe post this question to WooCommerce, maybe on their forum, if they have one. - bitoolean
I opened also there, but asked also here, because have huge Woocommerce developers, so may get some answer or tip. - DrMTR

1 Answers

1
votes

First, thanks for your Post, I was almost thinking I'm the only one with this need.

So far, this worked for my shop. I'm shure my code is not very versatile for different shop settings. Maybe someone could make a more general usable version.

Edit: I've added a picture showing the two rates. Image of the result and I've found a minor mistake calculating the shipping tax, corrected now.

/**
 * Change Tax Amount including Shipping Taxes
 * Referencing to wc-cart-functions.php starting from Line 296
 *
*/
add_filter( 'woocommerce_cart_totals_order_total_html', 'woo_rename_tax_inc_cart', 10, 1 );
function woo_rename_tax_inc_cart( $value ) {
    /* Get all infos needed */
    $shipping_total = WC()->cart->shipping_total;
    $taxes = WC()->cart->get_taxes_total( true, true );
    $taxrate = 7.7;
    $newtaxes = ($shipping_total/(100+$taxrate)*$taxrate) + $taxes; // Shipping is 100% + taxrate %, so we deduct both percentages.

    /* Check if Shipment total is active */
    if ( ! empty($shipping_total) && $shipping_total != 0 ) { 
        if ( ! empty( $value ) ) {
            // Show Price /wc-cart-functions.php Line 297
            $value = '<strong>' . WC()->cart->get_total() . '</strong> ';
            $value .= '<small class="includes_tax">' . '(inkl. ' . wc_price( $newtaxes ) . ' MWST)' . '</small>';
        }
    }

    // Attach Tax Info to Price (single line)
    $value = str_ireplace( 'Tax', 'GST', $value );

    return $value;
}