WooCommerce - Essex Webdesign

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.

1 comment

Leave a comment