After installing the WooCommerce Checkout Add-Ons plugin to add additional information to an order, I found the ‘Total:’ and ‘Subtotal:’ order labels were no longer relevant. However, they were still being shown on my email templates, amongst the new order information text left by the customer.
$totals = $order->get_order_item_totals()
Before making any alterations, copy the email to your theme, so you’re not altering the core WooCommerce version. To remove the Total and Subtotal labels from your emails, look for the line in your email template;
if ( $totals = $order->get_order_item_totals() ) {
get_order_item_totals() – Before
<?php if ( $totals = $order->get_order_item_totals() ) { $i = 0; foreach ( $totals as $total ) { $i++; ?><tr> <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th> <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td> </tr><?php } } ?>
Then add the if statement (and endif).
get_order_item_totals() – After
<?php if ( $totals = $order->get_order_item_totals() ) { $i = 0; foreach ( $totals as $total ) { $i++; //start ignore total labels pt1 if (($total['label'] !== 'Total:') && ($total['label'] !== 'Subtotal:')) : //end ignore total labels pt1 ?> <tr> <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th> <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td> </tr> <?php //start ignore total labels pt2 endif; //end ignore total labels pt2 } } ?>
What the code does
If the order total label is not ‘Total:’ and not ‘Subtotal:’ show the order label details.
Thanks for this.
Hello there,
Can you tell me how to remove all of the Prices from the New customer order using this method?
Best,
Steven
I have a client who wants to remove the colons after Subtotal, Payment method, and Total. I tried this and it didn’t work:
if ( $item_totals ) {
$i = 0;
foreach ( $item_totals as $total ) {
$i++;
if ($total[‘label’] == ‘Total:’){$total[‘label’]==’Total’;}
if ($total[‘label’] == ‘Subtotal:’){$total[‘label’]==’Subtotal’;}
if ($total[‘label’] == ‘Payment method:’){$total[‘label’]==’Payment Method’;}
…
Any ideas for me? Thank you for this post as it is very helpful.