删除“为{country}估算" Woocommerce结帐页面中税额后的文字 [英] Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

查看:105
本文介绍了删除“为{country}估算" Woocommerce结帐页面中税额后的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Woocommerce在线商店中设置了19%的标准税额. Unfortunatley-现在在我的结帐页面的总金额下方(包括20,12€...以下的部分)后面有一个德国估计"文本(请参见下图).我猜它显示该文本是因为计算出的税额有很多小数点.

I set up a 19% standard tax amount in my Woocommerce Online-Shop. Unfortunatley - now there is a text "estimated for Germany" behind the (includes 20,12 €... part below the total-amount in my checkout page (see image below). I guess it displays the text because the calculated tax amount has a lot of decimals.

HTML

<small class="includes_tax">
(includes 
    <span class="woocommerce-Price-amount amount">20.12
        <span class="woocommerce-Price-currencySymbol">€<span>
    </span> estimated for Germany)
</small>

使用20%的税额则不是这种情况.

This is not the case by using a 20% tax amount.

如何删除德国估算"文本?

我找不到任何过滤器或html类来定位文本.

I was not able find any filter or html class to target the text.

推荐答案

负责的代码是

The responsable code is in there, located in wc_cart_totals_order_total_html() function.

因此我们可以使用钩在woocommerce_cart_totals_order_total_html过滤器钩子中的钩子函数,在这里我们将消除这种烦人的行为(增加了对2.6.x及更高版本的兼容性):

So we can use hooked function hooked in woocommerce_cart_totals_order_total_html filter hook, where we'll remove this annoying behavior (added compatibility for versions since 2.6.x and up):

add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_cart_totals_order_total_html', 20, 1 );
function custom_cart_totals_order_total_html( $value ){
    $value = '<strong>' . WC()->cart->get_total() . '</strong> ';

    // If prices are tax inclusive, show taxes here.
    $incl_tax_display_cart = version_compare( WC_VERSION, '3.3', '<' ) ? WC()->cart->tax_display_cart == 'incl'  : WC()->cart->display_prices_including_tax();
    if ( wc_tax_enabled() && $incl_tax_display_cart ) {
        $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  = '';
            $value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
        }
    }
    return $value;
}

此代码位于您的活动子主题(或主题)的function.php文件上.

This code goes on function.php file of your active child theme (or theme).

经过测试,可以正常工作.

Tested and works.

这篇关于删除“为{country}估算" Woocommerce结帐页面中税额后的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆