在WooCommerce上,每个具有不同(整数)值的产品都有自定义字段 days_manufacture .
此外,我有此代码在购物车页面上显示最高值为 "days of manufacture" 的消息:
add_action('woocommerce_before_cart', 'days_of_manufacture');
function days_of_manufacture() {
$day_txt = ' ' . __('day', 'your_theme_domain_slug' );
$days_txt = ' ' . __('days', 'your_theme_domain_slug' );
$text = __('Your Order will be produced in: ', 'your_theme_domain_slug' );
$max_days = 0;
foreach( WC()->cart->get_cart() as $cart_item )
if($cart_item['days_manufacture'] > $max_days)
$max_days = $cart_item['days_manufacture'];
if($max_days != 0) {
if ($max_days == 1)
$days_txt = $day_txt;
$output = $text . $max_days . $days_txt;
echo "<div class='woocommerce-info'>$output</div>";
}
}
现在我想在电子邮件中显示此消息 .
我怎样才能做到这一点?
谢谢
1 回答
你可以这样做,改变一点this answer to your previous question的功能,我还将此功能挂钩到订单通知电子邮件的 woocommerce_email_before_order_table 钩子 .
所以你将用这个替换现有的函数 . 并且还替换了两个模板中的插入函数(参见下文) .
此功能可以处理在模板中显示您的自定义动态消息(如前所述)和电子邮件通知中 .
这是代码:
此代码位于活动子主题(或主题)的function.php文件中,或者也可以放在任何插件文件中 .
The templates changes
现在,在您的活动子主题(或主题)中的两个模板中woocommerce templates folder:
your_theme/woocommerce/myaccount/view-order.php
your_theme/woocommerce/checkout/thankyou.php
您将更改此行:
通过这条线:
现在,自定义通知也显示在电子邮件中,仍可在 Thankyou view order 页面上继续使用
My account > Orders > view order `页面也是 .
参考文献:
WooCommerce - Custom notice on in Thankyou and “My account” view order pages
Template Structure + Overriding Templates via a Theme
Woocommerce template myaccount > view-order.php
Woocommerce template checkout > thankyou.php