我在 WooCommerce 中自定义订单电子邮件模板,需要将“送货”的标题更改为“送货”,并将“送货地址”更改为“送货地址”。我尝试了一个插件“Say What”来更改文本,但它没有用。有一个循环处理所有这些信息。
这是“email-order-details.php”页面中第 52 行的代码。
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
if($total['label'] === "Shipping"){
//make second-last above total somehow
}
else{
?><tr>
<th class="td" scope="row" colspan="3" 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:left; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>" colspan="1"><?php echo $total['value']; ?></td>
</tr><?php
}
}
}
我假设这是一个过滤器 Hook ,但我不确定如何使用它。
woocommerce_get_order_item_totals
最佳答案
可以使用下面的钩子(Hook)函数来完成:
add_filter( 'woocommerce_get_order_item_totals', 'renaming_shipping_order_item_totals', 10, 3 );
function renaming_shipping_order_item_totals( $total_rows, $order, $tax_display ){
// Only on emails notifications
if( ! is_wc_endpoint_url() )
$total_rows['shipping']['label'] = __('Delivery', 'woocommerce');
return $total_rows;
}
代码进入事件子主题(或事件主题)的 function.php 文件。经过测试并有效。
要将“送货地址”标签更改为“送货地址”,您需要复制/编辑模板 email-addresses.php
,替换:
_e( 'Shipping address', 'woocommerce' );
通过:
_e( 'Delivery address', 'woocommerce' );
关于php - 更改 Woocommerce 电子邮件表总计中的 "Shipping"标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961163/