【问题标题】:Changing Tax to GST within WordPress/WooCommerce在 WordPress/WooCommerce 中将税更改为 GST
【发布时间】:2015-03-05 05:37:08
【问题描述】:

我无法更改我网站上购物车页面中的措辞。由于我的商店在澳大利亚,我想将命名约定从 Tax 更改为 GST。我已经更改了语言文件(/wp-content/plugins/woocommerce/i18n/languages/woocommerce.pot),但它根本没有影响我的商店。

是否有其他方法可以更改购物车页面中的措辞?我可以在 /wp-content/themes/mytheme/woocommerce/ 中编辑任何 PHP 文件吗?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    将税收总额显示为单个总额

    add_filter( 'woocommerce_countries_tax_or_vat', function () {
      return __( 'GST', 'woocommerce' );
    });
    

    其他例子

    add_filter( 'woocommerce_countries_inc_tax_or_vat', function () {
      return __( 'GST', 'woocommerce' );
    });
    
    add_filter( 'woocommerce_countries_ex_tax_or_vat', function () {
      return __( 'GST', 'woocommerce' );
    });
    

    【讨论】:

    • 你的答案与你之前 2 年 @som 给出的答案有何不同。
    【解决方案2】:

    有可用的过滤器。将它们包含在主题的 functions.php 文件中:

    /wp-content/themes/mytheme/functions.php

    add_filter( 'woocommerce_countries_inc_tax_or_vat', function () {
      return __( '(incl. GST)', 'woocommerce' );
    });
    

    WooCommerce 2.3.8、PHP 5.3+

    另见:woocommerce_countries_tax_or_vat & woocommerce_countries_ex_tax_or_vat

    过滤器和操作用于修改和扩展核心功能(不编辑任何可能被更新覆盖的内容)。

    查看WooCommerce docs。他们带着这种东西进城。

    【讨论】:

      【解决方案3】:

      终于解决了同样的问题:

      要修改的文件在“includes > class-wc-countries.php”

      【讨论】:

      • 直接覆盖插件文件是不好的做法;除其他事项外,插件的任何未来更新都可能会覆盖您的更改。大多数插件,包括 WooCommerce,都提供了挂钩,让您可以安全地修改/覆盖输出。
      【解决方案4】:

      替换 WooCommerce 购物车和结帐页面中的“包括 $xx.xx 税”

      在主题的functions.php文件中包含以下代码:

      add_filter( 'woocommerce_cart_totals_order_total_html', 'woo_rename_tax_inc_cart', 10, 1 );
      
      function woo_rename_tax_inc_cart( $value ) {
          $value = str_ireplace( 'Tax', 'GST', $value );
          return $value;
      }
      

      【讨论】:

        猜你喜欢
        • 2021-01-01
        • 2015-05-12
        • 2018-10-18
        • 2017-06-03
        • 2021-08-09
        • 2021-05-28
        • 1970-01-01
        • 2017-12-06
        • 2012-09-17
        相关资源
        最近更新 更多