I'm using the below function to add a custom total to the cart and checkout pages (taken from this answer to my question Insert a custom total excluding products cost row on cart and checkout totals in WooCommerce)
function display_custom_total() {
// Get (sub)total
$subtotal = WC()->cart->subtotal;
$total = WC()->cart->total;
// Calculate
$total_to_pay = $total - $subtotal;
// The Output
echo ' <tr class="cart-total-to-pay">
<th>' . __( 'Total (to pay)', 'woocommerce' ) . '</th>
<td data-title="total-to-pay">' . wc_price( $total_to_pay ) . '</td>
</tr>';
}
add_action( 'woocommerce_cart_totals_after_order_total', 'display_custom_total', 20 );
add_action( 'woocommerce_review_order_after_order_total', 'display_custom_total', 20 );
How can I add this to the order totals table in the emails as well?
I can add it to the email templates using the same function with the hook woocommerce_email_after_order_table but that adds it below the order table rather than as an extra row.
I know that I can edit the email template files in my child theme (particularly email-order-details.php ) but I'm not sure how to edit it to add the calculation into a new table row below this one:
<tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['label'] ); ?></th>
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['value'] ); ?></td>
</tr>
I also need to add it to the page in My Account > View Order (if it can be part of the same function).