隐藏Woocommerce电子邮件通知中特定产品类别的价格商品

隐藏Woocommerce电子邮件通知中特定产品类别的价格商品

问题描述:

我正在使用WooCommerce 3.1.1,我试图用客户和管理员的新订单通知中的特定产品类别的某些文本替换“价格金额”。隐藏Woocommerce电子邮件通知中特定产品类别的价格商品

我几乎已经尝试了一切,但我无法找到电子邮件通知的订单项明细表。

此邮件看起来是这样的现在:

Email

任何帮助将非常感激。

+0

您是否尝试编辑电子邮件模板? – Spartacus

+0

我找不到代码。 –

您需要先阅读这个官方文件,以了解Overriding WooCommerce Templates via your active Theme

,你需要改变的模板和倍率emails/email-order-items.php

在您的WC版本线58(或线55 WC版本3.2+),你将取代:

<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> 

得到你需要将你的活动子主题的function.php文件(或活动主题)添加此电子邮件ID:

// 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; 
} 

现在你会得到这样当产品类别的比赛和“新秩序”(管理员),“客户在保留令”和“客户处理顺序”。电子邮件通知只:

enter image description here

+0

此代码适用于发送给管理员但不发送给客户的电子邮件。 –

+0

@MujtabaK **更新:**由于“新订单”电子邮件通知只发送给管理员,我在if语句中添加了“客户等待订单”和“客户处理订单”电子邮件通知......这样,客户就可以收到它太。 – LoicTheAztec

+0

我更新了代码,但我无法对其进行测试。在结帐页面上,它返回它显示错误“内部服务器错误条纹”。 –