你可以做到这一点,稍微改变这个答案的功能到你之前的问题,我还挂钩这个功能来woocommerce_email_before_order_table
挂钩订单通知电子邮件。
因此,您将用这个替换现有的功能。并且您还替换了两个模板中的插入函数(见下文)。
此功能可以处理在模板(和以前一样)和电子邮件通知中显示您的自定义动态消息。
这是代码:
add_action('woocommerce_email_before_order_table', 'days_of_manufacture_view_order_and_email', 99);
function days_of_manufacture_view_order_and_email($order, $type='email') {
$day_txt = ' ' . __('day', 'your_theme_domain_slug' );
$days_txt = ' ' . __('days', 'your_theme_domain_slug' );
$max_days = 0;
// Your customized style for the email template (to adapt for your needs)
$style = 'border:solid 2px #ededed; padding:10px; font-weight:bold;';
// Your customized text goes in here
$text = __('Your Order will be produced in: ', 'your_theme_domain_slug' );
foreach( $order->get_items() as $item )
if(get_post_meta($item['product_id'], 'days_manufacture', true) > $max_days )
$max_days = get_post_meta($item['product_id'], 'days_manufacture', true);
if($max_days != 0) {
if ($max_days == 1)
$days_txt = $day_txt;
$output = $text . $max_days . $days_txt;
// displayed on the email notifications
if($type == 'email')
echo "<div class='woocommerce-info' style='$style'>$output</div>"; // <== Customize the styles if needed
// displayed on the woocommerce templates
else
echo "<div class='woocommerce-info' style='display:block !important;'>$output</div>"; // displayed on the templates
}
}
此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
模板更改
现在在您的活动子主题(或主题)woocommerce
模板文件夹中的两个模板中:
您将更改此行:
<?php days_of_manufacture_order_view($order); // <== inserted Here ?>
通过这一行:
<?php days_of_manufacture_view_and_email($order, 'template'); // <== inserted Here ?>
现在自定义通知也显示在电子邮件中,并且仍然适用于Thankyou
查看订单页面和
My account > Orders > view order
` 页也是。
参考: