1

I've set up VAT as including taxes for digital goods. In my cart and checkout the tax appears after the total amount as:

"(includes $xy VAT)"

I would rather much prefer what I saw on other shop sites:

"(includes $xy VAT estimated for Germany)"

My question:

1) is this a customization by the theme I'm using, is it a plug-in or can I set this up in WooCommerce myself? Is the estimated country on the cart set up by geolocation?

2) can I position the estimated tax text before the price with a hook or filter?

mujuonly
  • 11,370
  • 5
  • 45
  • 75
mika2019
  • 404
  • 4
  • 16

2 Answers2

1

For question 2 give this a try

add_filter( 'woocommerce_cart_total', 'wc_prefix_text_on_price' ); 

function wc_prefix_text_on_price( $price ) {
    $prefix = 'estimated tax';
    return  $prefix . $price;
}
mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • great, thanks. I've edited your answer and switched $suffix and $price... now, we just have to find the actual estimated tax value, so the $suffix can be something like: includes $ TAXVALUE VAT ... the masterpiece would than be: includes $ TAXVALUE vat estimated for GEOLOCATED COUNTRY – mika2019 Mar 14 '19 at 17:39
  • funny thing: when I select Hungary or Italy in the country field on the Checkout page, it shows: estimated for Hungary/Italy... for other EU countries like Germany ect it only shows includes VAT and not the estimated for country line... weird... can anyone confirm this? still very interested in how to get this whole includes $xy VAT text in front of the total amount/price! the solution above doesn't really fix this. – mika2019 Mar 15 '19 at 12:38
0

To change the "includes -- VAT estimated for [country]" message on the WooCommerce checkout page, you can use the woocommerce_cart_totals_shipping_html filter.

Here's an example of how to change the message:

add_filter( 'woocommerce_cart_totals_shipping_html', 'custom_checkout_vat_message' );

function custom_checkout_vat_message( $shipping_html ) {
// Get the customer's country
$customer_country = WC()->customer->get_shipping_country();

// Get the tax rate for the customer's country
$tax_rate = WC_Tax::get_rates( $customer_country )[1]['rate'];

// Calculate the VAT amount
$vat_amount = WC()->cart->shipping_total * $tax_rate / 100;

// Format the VAT amount as a price
$formatted_vat = wc_price( $vat_amount );

// Replace the message with your custom message
$new_message = 'Price includes VAT of ' . $formatted_vat . ' for ' . $customer_country;
$shipping_html = str_replace( 'includes ' . wc_price( WC()->cart->get_shipping_tax() ) . ' VAT estimated for ' . $customer_country, $new_message, $shipping_html );

return $shipping_html;

}

In this example, we're using the WC_Tax::get_rates() method to get the tax rate for the customer's country, and then calculating the VAT amount based on the shipping total of the cart. We're then using wc_price() to format the VAT amount as a price, and replacing the original message with our custom message using str_replace().