First of all, I modified your existing code. This because:
- It is not necessary to add the same code several times, since everything can happen once.
- The use of
WC()->cart
is not necessary, as $cart
is passed by default to the callback function.
So just use:
function action_woocommerce_cart_calculate_fees( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Getters
$contents_total = $cart->get_cart_contents_total();
$shipping_total = $cart->get_shipping_total();
$total = $contents_total + $shipping_total;
// 1
// Add fee
$cart->add_fee( __( 'TOTAL', 'woocommerce' ), $total );
// 2
// Calculate
$retraitsubt = $total *-1;
// Add fee
$cart->add_fee( __( 'A retirer', 'woocommerce' ), $retraitsubt );
// 3
// Calculate
$total_minus_100 = ( $total / 2 ) * -1;
// Add fee
$cart->add_fee( __( 'Acompte versé par CB', 'woocommerce' ), $total_minus_100 );
}
add_action( 'woocommerce_cart_calculate_fees', 'action_woocommerce_cart_calculate_fees', 10, 1 );
To answer your question:
You can use the woocommerce_email_styles
filter hook, which will allow you to add CSS to the emails versus having to overwrite the template files
So you get:
// Add CSS to email
function filter_woocommerce_email_styles( $css, $email ) {
$extra_css = 'tfoot tr:nth-child(5) { display: none !important; }';
return $css . $extra_css;
}
add_filter( 'woocommerce_email_styles', 'filter_woocommerce_email_styles', 10, 2 );
Note: Because the above answer via the filter hook is quite 'tricky' because no CSS class are assigned to the <tr>
tag in the emails, overwriting the /emails/email-order-details.php file may be a 'safer' option.
- This template can be overridden by copying it to
yourtheme/woocommerce/emails/email-order-details.php.
Replace line 65 - 76 @version 3.7.0
if ( $item_totals ) {
$i = 0;
foreach ( $item_totals as $total ) {
$i++;
?>
<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>
<?php
}
}
With
if ( $item_totals ) {
$i = 0;
foreach ( $item_totals as $total ) {
$i++;
// Make sure this is correct!
$label = 'A retirer:';
// Check if the string is not equal to the label, and if not, display the table row
if ( $total['label'] != $label ) {
?>
<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>
<?php
}
}
}