【问题标题】:Hide price items for specific product categories in Woocommerce email notification在 Woocommerce 电子邮件通知中隐藏特定产品类别的价格项目
【发布时间】:2018-04-10 05:17:45
【问题描述】:

我正在使用 WooCommerce 3.1.1,我正在尝试将“价格金额”替换为针对客户和管理员的新订单通知中特定产品类别的一些文本。

我几乎尝试了所有方法,但找不到电子邮件通知的订单商品详细信息表。

这封电子邮件现在看起来像这样:

任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试编辑电子邮件模板?
  • 我找不到代码。

标签: php wordpress woocommerce categories email-notifications


【解决方案1】:

您需要首先阅读这份官方文档,了解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;
}

现在您将在产品类别匹配时收到此信息,并且仅限“新订单”(管理员)、“客户保留订单”和“客户处理订单”电子邮件通知:

【讨论】:

  • 此代码适用于发送给管理员但不发送给客户的电子邮件。
  • @MujtabaK 更新: 由于“新订单”电子邮件通知仅发送给管理员,我添加了“客户暂停订单”和“客户处理订单”电子邮件通知在 if 语句中......这样客户也会收到它。
  • 我更新了代码,但无法测试。在结帐页面上,它返回显示错误“Internal Server Error stripe”。
  • 另外,当我尝试通过后端测试发送电子邮件时,它会将我重定向到 post.php,并显示错误“解析错误:语法错误,意外'$formated_line_subtotal' (T_VARIABLE) in /home/clickableco/ public_html/demo3/wp-content/plugins/woocommerce/templates/emails/email-order-items.php 在第 72 行"
  • @MujtabaK 抱歉,) 末尾缺少 if( has_term( $categories, 'product_cat', $product-&gt;get_id() ) &amp;&amp; ( $email_id == 'new_order' || $email_id == 'customer_processing_order' || $email_id == 'customer_on_hold_order' ) ) ... 这次应该可以了
猜你喜欢
  • 2018-06-04
  • 2019-04-09
  • 1970-01-01
  • 2018-07-18
  • 2018-08-16
  • 2020-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多