Customize the text quot;Totalquot; in WooCommerce checkout page(自定义文本“总计在 WooCommerce 结帐页面中)
问题描述
我想将结帐页面中的Total"文本更改为Totalinkl.vat".我尝试过不同的事情但没有成功......
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.
请问我怎样才能做到这一点?
How can I achieve this please?
谢谢
推荐答案
OPTION 1 (最佳选择)
覆盖woocommerce checkout/review-order.php 模板.
Overriding the woocommerce checkout/review-order.php template.
您首先需要(如果没有完成)复制templates 位于 的子文件夹>woocommerce 插件文件夹到您的活动子主题(或主题)文件夹,并将其重命名为 woocommerce.
You need first (if not done) to copy the
templatessub folder located in inwoocommerceplugin folder to your active child theme (or theme) folde, and rename itwoocommerce.
在您的活动主题中完成后,转到 woocommerce >结帐,然后打开/编辑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…
参考文献:
- 模板结构 + 通过主题覆盖模板
- Woocommerce 模板结帐 > 审查订单.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 结帐页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自定义文本“总计"在 WooCommerce 结帐页面中
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
