从 WooCommerce 订单详细信息表中删除退款行
我想从 WooCommerce 订单详细信息表中删除退款行
从 /order/order-details.php WooCommerce 模板文件:
<?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
}
?>
为此,我使用以下过滤器挂钩:
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 );
这不会给出任何错误消息,但也不会得到所需的结果。该行未被删除。有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我们查看 /includes/class -wc-order.php 详细我们看到使用了以下函数WooCommerce 用于添加总退款行。
由于订单可能包含多项退款,因此
'refund_' 。 $id
与'refund'
相反使用,因此要删除它,您必须使用循环。所以你得到:
When we look at /includes/class-wc-order.php in detail we see the following function is used in WooCommerce for adding the total refunds row(s).
Since an order can consist of several refunds,
'refund_' . $id
is used opposite'refund'
So to remove it, you have to use a loop. So you get: