您需要首先阅读这份官方文档,了解Overriding WooCommerce Templates via your active Theme
您需要更改和覆盖的模板是emails/email-order-items.php
在您的 WC 版本的第 58 行(或 WC 版本 3.2+ 中的第 55 行),您将替换:
<td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
通过这个(您应该在其中设置自己的类别和替换文本字符串):
<?php
## ---- Variables to define (below)---- ##
$categories = array( 'clothing' ); // The Product categories coma separated (IDs slugs or names)
$replacement_text = __( 'Replacement text (here)' ); // The replacement text
// Getting the email ID global variable (From our function below)
$refNameGlobalsVar = $GLOBALS;
$email_id = $refNameGlobalsVar['email_id_str'];
// When matching product categories, "New Order", "Processing" and "On Hold" email notifications
if( has_term( $categories, 'product_cat', $product->get_id() )
&& ( $email_id == 'new_order' || $email_id == 'customer_processing_order' || $email_id == 'customer_on_hold_order' ) )
$formated_line_subtotal = $replacement_text;
else
$formated_line_subtotal = $order->get_formatted_line_subtotal( $item );
?>
<td class="td" style="text-align:<?php echo $text_align; ?>; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo $formated_line_subtotal; ?></td>
要获取电子邮件 ID,您需要将其添加到活动子主题 (或活动主题)的 function.php 文件中:
// Setting the email_id as a global variable
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email){
$GLOBALS['email_id_str'] = $email->id;
}
现在您将在产品类别匹配时收到此信息,并且仅限“新订单”(管理员)、“客户保留订单”和“客户处理订单”电子邮件通知: