【问题标题】:Customize the text "Total" in WooCommerce checkout page在 WooCommerce 结帐页面中自定义文本“总计”
【发布时间】:2017-01-20 08:19:06
【问题描述】:

我想将结帐页面中的“Total”文本更改为“Total inkl.vat”。我尝试了不同的事情但没有成功……

这是我的目标:

<?php _e( 'Total', 'woocommerce' ); ?>

这是代码 sn-p。我搜索了所有语言文件,但找不到任何东西。我已经安装了 Q 翻译插件,但我认为这不是问题。

我可以努力编码,但这不是一个好的解决方案,因为我必须在我的所有文件中进行此编辑。

请问我怎样才能做到这一点?

谢谢

【问题讨论】:

  • 您的整个网站是否都使用某种语言,只是那一行没有翻译?或者您想更改翻译?

标签: php wordpress woocommerce checkout gettext


【解决方案1】:

选项 1 (最佳选项)

Overriding the woocommercecheckout/review-order.php 模板。

您需要先(如果未完成)复制 templates 子文件夹位于 woocommerce 插件文件夹到您的活动子主题(或主题)文件夹,并将其重命名为 woocommerce

完成活动主题后,转到 woocommerce &gt; checkout,然后打开/编辑 review-order.php 模板文件。

在这个模板的最后你有这个:

        <?php do_action( 'woocommerce_review_order_before_order_total' ); ?>

        <tr class="order-total">
            <th><?php _e( 'Total', 'woocommerce' ); ?></th>
            <td><?php wc_cart_totals_order_total_html(); ?></td>
        </tr>

        <?php do_action( 'woocommerce_review_order_after_order_total' ); ?>

    </tfoot>
</table>

所以你会改变:

<th><?php _e( 'Total', 'woocommerce' ); ?></th>

收件人:

<th><?php _e( 'Total inkl. vat', 'woocommerce' ); ?></th>

现在可以保存了,大功告成……

参考资料:


选项 2 (不理想,见下文)

您可以为此目的使用 wordpress gettex() 本机函数,这样:

add_filter('gettext', 'wc_renaming_checkout_total', 20, 3);
function wc_renaming_checkout_total( $translated_text, $untranslated_text, $domain ) {

    if( !is_admin() && is_checkout ) {
        if( $untranslated_text == 'Total' )
            $translated_text = __( 'Total inkl. vat','theme_slug_domain' );
    }
    return $translated_text;
}

此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

但是您会在价格表中获得 2 个自定义文本,因为有 2 个 "Total" 文本(在第一行在“产品”之后)和最后一次......

此代码已经过测试并且可以工作。

【讨论】:

  • link@LoicTheAztec
  • @loictheaztec - 我使用了你的解决方案来解决这个问题related question,但注意到你的代码和 cmets 在我对我对你的建议所做的调整进行投票和评论之前就已经消失了。如果您可以将回复放回去,那么我会感谢您,并可能将其链接为相关问题。
  • @Les 抱歉,我已取消删除我的答案。
  • @LoicTheAztec 有什么技巧可以只针对选项 2 中的两个刺中的一个吗?
猜你喜欢
  • 2016-07-29
  • 2018-08-18
  • 2021-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-10
  • 2015-07-29
  • 2022-01-23
相关资源
最近更新 更多