[英]Remove the shipping row from the order table in Woocommerce email notifications
通過主題覆蓋 woocommerce 模板<\/a>,刪除電子郵件通知中的發貨行可以輕松完成,只需向
emails\/email-order-details.php<\/code>模板添加少量代碼。
這是從
line 51<\/code><\/strong>開始的摘錄。
因此,您將使用以下代碼替換所有代碼 beetwen html 打開
<tfoot><\/code>標記和關閉
<\/tfoot><\/code>標記:
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $key_total => $total ) {
$i++;
if( $key_total != 'shipping' ):
?><tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
<td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
</tr><?php
endif;
}
}
if ( $order->get_customer_note() ) {
?><tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>;"><?php _e( 'Note:', 'woocommerce' ); ?></th>
<td class="td" style="text-align:<?php echo $text_align; ?>;"><?php echo wptexturize( $order->get_customer_note() ); ?></td>
</tr><?php
}
?>
</tfoot>
擴展@LoicTheAztec 並於 2022 年更新:
將“email-order-details.php”WooCommerce 模板中的<tfoot>
替換為以下代碼。 主要變化是:
key_total
key_total === 'shipping'
添加條件以忽略打印行<tfoot>
<?php
$item_totals = $order->get_order_item_totals();
if ( $item_totals ) {
$i = 0;
// Add "$key_total" to be able to grab the key name
foreach ( $item_totals as $key_total => $total ) {
$i++;
// Add conditional to only print row if row key is not "shipping"
if( $key_total !== 'shipping' ):
?>
<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
endif;
}
}
if ( $order->get_customer_note() ) {
?>
<tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Note:', 'woocommerce' ); ?></th>
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo wp_kses_post( nl2br( wptexturize( $order->get_customer_note() ) ) ); ?></td>
</tr>
<?php
}
?>
</tfoot>
我們可以在訂單詳細信息 object 中看到如何布置鍵名的示例。 下圖來自打印$order->get_order_item_totals();
到錯誤日志
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.