【问题标题】:Remove woocommerce cart (estimated by country) tax text删除 woocommerce 购物车(按国家/地区估计)税款文本
【发布时间】:2018-10-20 12:00:33
【问题描述】:

我正在用 wordpress 建立一个网站,当我进入购物车时,它不断弹出

“(澳大利亚估计)”紧跟在 TAX 之后,然后给出项目的税值。

我在这里查看了另一个问题和答案,但他们的代码与我的代码不同。我尝试了一些不同的方法,但无法弄清楚。

这是我在谷歌浏览器上检查购物车时的代码。

<tr class="tax-total">
    <th>Tax <small>(estimated for Australia)</small></th>
    <td data-title="Tax">
       <span class="woocommerce-Price-amount amount">
       <span class="woocommerce-Price-currencySymbol">$</span>109.80</span> 
    </td>
</tr>

有人可以帮我找出过滤器修复方法吗?

【问题讨论】:

    标签: php wordpress woocommerce cart tax


    【解决方案1】:

    您可以通过编辑主题的 WooCommerce 购物车模板文件来实现。我猜这是在 cart.php 中硬编码的。

    或者,如果您想要更简单的解决方案,只需使用 CSS 将其隐藏。

    此代码隐藏了“(估计为 {country})”部分:

    .tax-total th small {display:none!important}
    

    这个隐藏

    .tax-total {display:none!important}
    

    【讨论】:

      【解决方案2】:

      负责该行为的函数是wc_cart_totals_order_total_html() ...但希望您可以使用以下代码挂钩函数来更改它:

      add_filter( 'woocommerce_cart_totals_order_total_html', 'filtering_cart_totals_order_total_html', 20, 1 );
      function filtering_cart_totals_order_total_html( $value ){
          $value = '<strong>' . WC()->cart->get_total() . '</strong> ';
      
              // If prices are tax inclusive, show taxes here.
          if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
              $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 ) ) {
                  $value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
              }
          }
          return $value;
      }
      

      代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

      你会得到:

      代替:

      这是 Woocommerce 3.2+ 的更新,略有不同,基于此答案:Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

      【讨论】:

        猜你喜欢
        • 2021-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-17
        • 1970-01-01
        • 1970-01-01
        • 2020-11-28
        • 2017-01-18
        相关资源
        最近更新 更多