自定义文本“总计"在WooCommerce结帐页面 [英] Customize the text "Total" in WooCommerce checkout page

查看:75
本文介绍了自定义文本“总计"在WooCommerce结帐页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将结帐页面中的总计"文本更改为总计墨水量".我尝试了不同的尝试而没有成功……

I would like to change the the "Total" text in my checkout page to "Total inkl. vat". I have tried different things without success…

这是我的目标:

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

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

This is the code snippet. I've searched in all language files but i can't find anything. I've installed the Q translate plugin but I don't think it's the problem.

我可以编写困难代码,但这并不是一个好的解决方案,因为我必须在所有文件中进行此编辑.

I could code it hard, but thats not a good solution because I've to do this edit in all my files.

请问如何实现?

谢谢

推荐答案

选项1 (最佳选择)

覆盖woocommerce checkout/review-order.php 模板.

Overriding the woocommerce checkout/review-order.php template.

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

You need first (if not done) to copy the templates sub folder located in in woocommerce plugin folder to your active child theme (or theme) folde, and rename it woocommerce.

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

Once done in your active theme go to woocommerce > checkout, and open/edit review-order.php template file.

在此模板的结尾处,您具有以下内容:

At the end of this template you have this:

        <?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>

现在您可以保存,您就完成了……

Now you can save, you are done…

参考:

  • Template Structure + Overriding Templates via a Theme
  • Woocommerce template checkout > review-order.php

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

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

You could use wordpress gettex() native function for that purpose, this way:

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文件中,也可能会出现在任何插件文件中.

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

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

But you will get 2 customized texts in the prices table, because there is 2 "Total" texts (once in the first line after 'Products') and one time at the end…

此代码已经过测试并且可以正常工作.

这篇关于自定义文本“总计"在WooCommerce结帐页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆