問題描述
我想將結(jié)帳頁面中的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…
這是我的目標(biāo):
<?php _e( 'Total', 'woocommerce' ); ?>
這是代碼片段.我搜索了所有語言文件,但找不到任何內(nèi)容.我已經(jīng)安裝了 Q 翻譯插件,但我認(rèn)為這不是問題.
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.
我可以編碼很困難,但這不是一個(gè)好的解決方案,因?yàn)槲冶仨氃谖业乃形募羞M(jìn)行此編輯.
I could code it hard, but thats not a good solution because I've to do this edit in all my files.
請(qǐng)問我怎樣才能做到這一點(diǎn)?
How can I achieve this please?
謝謝
推薦答案
OPTION 1 (最佳選擇)
覆蓋woocommerce checkout/review-order.php
模板.
Overriding the woocommerce checkout/review-order.php
template.
您首先需要(如果沒有完成)復(fù)制templates
位于 的子文件夾>woocommerce
插件文件夾到您的活動(dòng)子主題(或主題)文件夾,并將其重命名為 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
.
在您的活動(dòng)主題中完成后,轉(zhuǎn)到 woocommerce >結(jié)帳
,然后打開/編輯review-order.php
模板文件.
Once done in your active theme go to woocommerce > checkout
, and open/edit
review-order.php
template file.
在此模板的末尾,您會(huì)看到:
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>
所以你會(huì)改變:
<th><?php _e( 'Total', 'woocommerce' ); ?></th>
致:
<th><?php _e( 'Total inkl. vat', 'woocommerce' ); ?></th>
現(xiàn)在你可以保存了,你完成了……
Now you can save, you are done…
參考文獻(xiàn):
- 模板結(jié)構(gòu) + 通過主題覆蓋模板
- Woocommerce 模板結(jié)帳 > 審查訂單.php
選項(xiàng) 2 (不理想,見下文)
你可以使用 wordpress gettex()
用于此目的的本機(jī)函數(shù),如下所示:
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;
}
此代碼位于活動(dòng)子主題(或主題)的 function.php 文件或任何插件文件中.
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
但是你會(huì)在價(jià)格表中得到2個(gè)自定義文本,因?yàn)橛?個(gè)"Total"
文本(一次在產(chǎn)品"之后的第一行)和最后一次......
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…
此代碼已經(jīng)過測(cè)試且有效.
這篇關(guān)于自定義文本“總計(jì)"在 WooCommerce 結(jié)帳頁面中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!