I want to remove the refund row from the WooCommerce order details table
Existing code copied from /order/order-details.php WooCommerce template file:
<?php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th class="row" scope="row"><?php echo esc_html( $total['label'] ); ?></th>
<td class="row" scope="row"><?php echo ( 'payment_method' === $key ) ? esc_html( $total['value'] ) : wp_kses_post( $total['value'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php
}
?>
For this I use the following filter hook:
function customize_woocommerce_get_order_item_totals( $total_rows, $order, $tax_display ) {
unset($total_rows['refund']);
return $total_rows;
}
add_filter( 'woocommerce_get_order_item_totals', 'customize_woocommerce_get_order_item_totals', 10, 3 );
This does not give any error messages, but also not the desired result. The row is not deleted. Any advice?