In WooCommerce I have a problem on my thankyou page (once the customer has placed his order). 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"
Also I want to remove the red bordered rectangle block: "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.
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. 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.
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: