自定义文本“总计"在 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
templates
sub folder located in inwoocommerce
plugin 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…
此代码已经过测试且有效.
相关文章