【问题标题】:Remove "estimated for {country}" text after tax amount in Woocommerce checkout page在 Woocommerce 结帐页面中删除税额后的“估计为 {country}”文本
【发布时间】:2018-07-26 09:52:03
【问题描述】:

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

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

如何去掉“estimated for Germany”文字?

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

【问题讨论】:

    标签: php wordpress woocommerce checkout tax


    【解决方案1】:

    责任代码为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 文件中。

    经过测试并且有效。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2019-08-05
        • 1970-01-01
        • 2018-10-20
        • 2017-01-20
        • 2016-06-15
        • 2014-08-17
        • 2017-06-16
        • 2021-04-03
        • 2018-10-01
        相关资源
        最近更新 更多