[英]WooCommerce - Customize “Total” text on Thankyou order received page
In WooCommerce I have a problem on my thankyou page (once the customer has placed his order). 在WooCommerce中,我的“谢谢”页面上有问题(一旦客户下了订单)。 I have tryed to change it manualy but the problem is that the code is generated in an unknown file which I can't find. 我试图手动更改它,但是问题是代码是在找不到的未知文件中生成的。
<tfoot>
<?php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
?>
</tfoot>
This code give me all information in my order like a coupon the shipping etc. 此代码为我提供了订单中的所有信息,例如优惠券,运费等。
On this picture I would like to replace the text in the black bordered rectangle (Here 'Gesamt:'
mean "Total"
by "Total inkl. vat"
在此图片上,我要替换黑色边框中的文本(此处的'Gesamt:'
意思是"Total"
为"Total inkl. vat"
'Gesamt:'
"Total inkl. vat"
Also I want to remove the red bordered rectangle block: "Inkl. 19% MwSt."
我也想删除"Inkl. 19% MwSt."
红色边框的矩形块: "Inkl. 19% MwSt."
. 。
Is it possible? 可能吗?
How can I do it? 我该怎么做?
Thanks. 谢谢。
Here the extract of the end on woocommerce/order/order-details.php
template that is loaded in thank you page. 这是woocommerce/order/order-details.php
模板上woocommerce/order/order-details.php
的摘录,该模板已在“谢谢”页面中加载。
To override the
'Total'
text displayed byforeach
loop with the methodget_order_item_totals()
applied to the$order
object (that generate an array ofkey/values
) , you have to add a condition for each language used by your web site. 要使用适用于$order
对象(生成key/values
数组get_order_item_totals()
的方法get_order_item_totals()
覆盖foreach
循环显示的'Total'
文本,您必须为网站使用的每种语言添加条件。 Here in my code you got english and german. 在我的代码中,您得到了英语和德语。
In your active theme go to woocommerce > order
, and open/edit order-details.php
template file. 在您的活动主题中,进入woocommerce > order
,然后打开/编辑order-details.php
模板文件。
Replace the end of your template with this: 以此替换模板的结尾:
<tfoot>
<?php
$order_item_totals = $order->get_order_item_totals();
$count_lines = count($order_item_totals) - 1;
$count = 0;
foreach ( $order_item_totals as $key => $total ) {
$count++;
// The condition to replace "Total:" text in english and german
if( $total['label'] == 'Total:' || $total['label'] == 'Gesamt:')
$total_label = __( 'Total inkl. vat:', 'woocommerce' );
else
$total_label = $total['label'];
// End of the condition
?>
<tr>
<th scope="row"><?php echo $total_label; // <== == Replaced $total['label'] by $total_label ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
// this should avoid displaying last line
if( $count >= $count_lines ) break;
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_order_details_after_order_table', $order ); ?>
<?php if ( $show_customer_details ) : ?>
<?php wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) ); ?>
<?php endif; ?>
Now you can save, you are done… 现在您可以保存,完成了……
This code is tested and works. 此代码已经过测试并且可以工作。
References: 参考文献:
Hey I think this would work for you 嘿,我认为这对您有用
Just make sure that inkl. 19%....
只要确保inkl. 19%....
inkl. 19%....
is correctly written. inkl. 19%....
正确书写。
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo ($total['label']=='inkl. 19% Mwst.'?'Vat Only':$total['label']); ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.