【问题标题】:Remove "shipping subtotal" from Woocommerce's new order emails从 Woocommerce 新订单电子邮件中删除“运输小计”
【发布时间】:2017-09-16 05:09:47
【问题描述】:
我已尝试取消设置代码,但它也删除了总计。我想保留总计并删除运费总计。
<?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
}
}
?>
我似乎找不到解决方案。有什么建议吗?
谢谢。
【问题讨论】:
标签:
php
wordpress
woocommerce
shipping
orders
【解决方案1】:
要删除 shipping subtotal 行,请改用以下代码:
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total_key => $total ) { // Changed HERE
$i++;
if( 'shipping' != $total_key ){ // Added HERE
?><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
} // Added HERE
}
}
?>
或者你可以使用unset() php函数:
<?php
if ( $totals = $order->get_order_item_totals() ) {
unset(totals['shipping']) // HERE
$i = 0;
foreach ( $totals as $total_key => $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
}
?>