在 WooCommerce 电子邮件中查找/编辑订单详细信息元文本
Find / Edit the order details meta text on WooCommerce emails
我正在尝试将客户电子邮件翻译成中文,但我在源代码中找不到这些:
我已经找到了其他所有内容,我认为这些也是硬编码的,但我无法在代码中找到它们。
这在我的 email-order-details.php
文件中:
<?php
$totals = $order->get_order_item_totals();
if ( $totals ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?>
<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
}
}
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( wptexturize( $order->get_customer_note() ) ); ?></td>
</tr>
<?php
但我看不到在哪里可以更改以下内容:
- 小计:
- 折扣:
- 运费:
- 支付方式:
- 总计:
- 税收:
通过名为 gettext
的 built-in WordPress 过滤器翻译字符串可能是更好的使用方法,特别是因为翻译应该在整个站点范围内进行,而不仅仅是在电子邮件中,如下例:
add_filter( 'gettext', 'my_custom_string_translation', 999, 3 );
function my_custom_string_translation( $translated, $text, $domain ) {
$translated = str_ireplace( 'Subtotal', 'Your translation here.', $translated );
$translated = str_ireplace( 'Discount', 'Your translation here.', $translated );
$translated = str_ireplace( 'Shipping', 'Your translation here.', $translated );
$translated = str_ireplace( 'Payment Method', 'Your translation here.', $translated );
$translated = str_ireplace( 'Total', 'Your translation here.', $translated );
return $translated;
}
您可以将上面的代码放入您的 functions.php
或自定义插件文件中。
我正在尝试将客户电子邮件翻译成中文,但我在源代码中找不到这些:
我已经找到了其他所有内容,我认为这些也是硬编码的,但我无法在代码中找到它们。
这在我的 email-order-details.php
文件中:
<?php
$totals = $order->get_order_item_totals();
if ( $totals ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?>
<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
}
}
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( wptexturize( $order->get_customer_note() ) ); ?></td>
</tr>
<?php
但我看不到在哪里可以更改以下内容:
- 小计:
- 折扣:
- 运费:
- 支付方式:
- 总计:
- 税收:
通过名为 gettext
的 built-in WordPress 过滤器翻译字符串可能是更好的使用方法,特别是因为翻译应该在整个站点范围内进行,而不仅仅是在电子邮件中,如下例:
add_filter( 'gettext', 'my_custom_string_translation', 999, 3 );
function my_custom_string_translation( $translated, $text, $domain ) {
$translated = str_ireplace( 'Subtotal', 'Your translation here.', $translated );
$translated = str_ireplace( 'Discount', 'Your translation here.', $translated );
$translated = str_ireplace( 'Shipping', 'Your translation here.', $translated );
$translated = str_ireplace( 'Payment Method', 'Your translation here.', $translated );
$translated = str_ireplace( 'Total', 'Your translation here.', $translated );
return $translated;
}
您可以将上面的代码放入您的 functions.php
或自定义插件文件中。