Remove (Includes %s)
-
Is there a working snippet to remove/hide the (Includes %s) ex tax in both site and email ?
All the solutions I’ve found do not work at all.Thanks
-
Hey @troglos,
If the prices of your products do not include tax, then you can change the tax setting to, “No, I will enter prices exclusive of tax,” and that will remove all of that text. This is under WooCommerce > Settings > Tax.
I know with all of the stores I’ve set up the tax was additional based on the shipping location, so it was added on after the fact.
Well in Italy the prices include the taxes, so I don’t need to show them separately.
Momentarily I’ve just replaced the translation in the .po with an empty space, but it’s not a clean solution.I am sure it’s possible to override the functions.
That’s good to know about the prices in Italy ??
This is the function that outputs the
(ex. tax)
text:/** * Include the Ex Tax label. * @return string */ public function ex_tax_or_vat() { $return = in_array( $this->get_base_country(), $this->get_european_union_countries( 'eu_vat' ) ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' ); return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return ); }
Since it applies filters, we can create this function:
function woo_ex_tax_filter( $content ) { if ( '(ex. tax)' == $content ) { $content = ''; } return $content; } add_filter( 'woocommerce_countries_ex_tax_or_vat', 'woo_ex_tax_filter', 99, 1 );
This will check to see if
(ex. tax)
is going to be output, and if so, it will remove it. It will only directly match(ex. tax)
, though. If this is being translated and no longer matches, it will not work.If you never need the tax or vat snippet displayed, then you can use this:
function woo_ex_tax_filter( $content ) { return ''; } add_filter( 'woocommerce_countries_ex_tax_or_vat', 'woo_ex_tax_filter', 99, 1 );
Hi Jesse,
I’ve tried your last snippet but it doesn’t work.
Back to the empty space in the .poBy the way, I see that there are only two places where the tax label (Includes %s) is used
this (in /includes/class-wc-order.php):
public function get_formatted_order_total( $tax_display = '' ) { $formatted_total = wc_price( $this->get_total(), array( 'currency' => $this->get_order_currency() ) ); $order_total = $this->get_total(); $total_refunded = $this->get_total_refunded(); $tax_string = ''; // Tax for inclusive prices if ( wc_tax_enabled() && 'incl' == $tax_display ) { $tax_string_array = array(); if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) { foreach ( $this->get_tax_totals() as $code => $tax ) { $tax_amount = $total_refunded ? wc_price( WC_Tax::round( $tax->amount - $this->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ), array( 'currency' => $this->get_order_currency() ) ) : $tax->formatted_amount; $tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label ); } } else { $tax_string_array[] = sprintf( '%s %s', wc_price( $this->get_total_tax() - $this->get_total_tax_refunded(), array( 'currency' => $this->get_order_currency() ) ), WC()->countries->tax_or_vat() ); } if ( ! empty( $tax_string_array ) ) { $tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ); } } if ( $total_refunded ) { $formatted_total = '<del>' . strip_tags( $formatted_total ) . '</del> <ins>' . wc_price( $order_total - $total_refunded, array( 'currency' => $this->get_order_currency() ) ) . $tax_string . '</ins>'; } else { $formatted_total .= $tax_string; } return apply_filters( 'woocommerce_get_formatted_order_total', $formatted_total, $this ); }
and this (in /includes/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->tax_display_cart == 'incl' ) { $tax_string_array = array(); if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) { foreach ( WC()->cart->get_tax_totals() as $code => $tax ) $tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label ); } else { $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 ) ) { $value .= '<small class="includes_tax">' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>'; } } echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value ); }
Ah, I misunderstood, I thought your were looking to remove the
ex.tax
part.These filters are a little hacky, but I was trying to target the HTML in the text strings and not the content. The first should work on the cart and checkout pages, the second works on order pages and emails.
function woo_includes_tax_text_filter_1( $content ) { // set up regex match, replace regex with nothing $find = '/\<small.*small\>/Ui'; $content = preg_replace( $find, '', $content ); return $content; } add_filter( 'woocommerce_cart_totals_order_total_html', 'woo_includes_tax_text_filter_1', 99, 1 ); function woo_includes_tax_text_filter_2( $content ) { // set up regex, find matches, take only first match and return it $find = '/\<span class\=\"amount\".*\<\/span\>/Ui'; preg_match( $find, $content, $matches ); $content = $matches[0]; return $content; } add_filter( 'woocommerce_get_formatted_order_total', 'woo_includes_tax_text_filter_2', 99, 1 );
Great, it’s finally working now!
PS
sorry for the ex.tax part, my mistakeNo worries, glad I could help.
Those functions should continue to work unless the output is changed by the Woo team, which probably won’t happen any time soon. You could also rename the functions if you wanted to, just make sure to rename the function name and how it’s called in
add_filter
.Thanks again
Hi, Guys.
I′ve tried use the last Jesses code, but does′t work for me.
Problem is, that after using code total coast is not showing. All field is empty included total price. I want to remove only thesee text “(included 20.5€ tax)”.
Have some solution for me please?Hey meldy, please open up your own ticket ?? there might be something else going on, and we like to keep things tidy. Thank you!
In my website I have added product with cost $100, and I have added tax rule only for AU customers 10% (tax including in product) in cart its shows as $100 (including $10.00).
I need to show cost as $100 for other country’s customers as a $100 (including $00.00). but now it’s shows as a $90(including $00.00) for other countries. how can I fixed this.
- The topic ‘Remove (Includes %s)’ is closed to new replies.