在Woocommerce结帐页面中删除税后金额后的“估算{country}”文字

时间:2018-02-15 15:23:36

标签: php wordpress woocommerce checkout tax

我在Woocommerce Online-Shop中设置了19%的标准税额。 Unfortunatley - 现在有一个文本“估计德国”背后(包括20,12€...部分低于我的结帐页面中的总金额(见下图)。我猜它显示文本,因为计算的税额有很多小数。

enter image description here

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%的税额并非如此。

如何删除“估计德国”文字?

我无法找到任何过滤器或html类来定位文本。

2 个答案:

答案 0 :(得分:2)

责任代码为in there,位于wc_cart_totals_order_total_html()函数。

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

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文件中。

经过测试和工作。

答案 1 :(得分:0)

简单地从我使用的购物车总数中删除该文本:

add_filter( 'woocommerce_cart_totals_order_total_html', function ($html) {
    return substr($html, 0, strpos($html, '<small class="includes_tax">'));
}, 10, 2 );