WooCommerce 自定义邮件与客户的价格不同
WooCommerce custom mail different price than the customer
我以 20% 的折扣购买产品,然后在我的网站上以正常价格转售。
我想制作一封额外的电子邮件,当客户在我的网站上下订单时,必须将其发送到我自己的电子邮件地址。
我的问题:
如果可以制作一封新电子邮件,发送正常的付款详细信息,但也发送带有 20% 折扣的已付价格。
这对我以折扣价购买产品有很大帮助,这样我就可以将电子邮件发送给产品所有者。现在我必须计算正常价格的 20% 并将其发送给产品所有者。
有人有解决方案或提示吗?
感谢您的帮助。
您可以使用挂钩在 woocommerce_email_order_details
操作挂钩中的自定义函数,以“新订单”电子邮件通知为目标(发送给管理员),您将以这种方式添加这些详细信息:
add_action('woocommerce_email_order_details', 'new_order_custom_email_notification', 20, 4 );
function new_order_custom_email_notification( $order, $sent_to_admin, $plain_text, $email )
{
// Only for "New order" email notifications (admin)
if( $email->id != 'new_order' ) return;
$order_total = floatval($order->get_total());
$order_total_discount = $order_total * 0.2;
$order_total_discounted = $order_total - $order_total_discount;
// CSS style
$styles = '<style>
.discount-info table{width: 100%; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif;
color: #737373; border: 1px solid #e4e4e4; margin-bottom:8px;}
.discount-info table th, table.tracking-info td{text-align: left; border-top-width: 4px;
color: #737373; border: 1px solid #e4e4e4; padding: 12px; width:58%;}
.discount-info table td{text-align: left; border-top-width: 4px; color: #737373; border: 1px solid #e4e4e4; padding: 12px;}
</style>';
// HTML Structure
$html_output = '<h2>'.__('Reseller discount Information').'</h2>
<div class="discount-info">
<table cellspacing="0" cellpadding="6">
<tr>
<th>' . __('Order total') . '</th>
<td>' . wc_price($order_total) . '</td>
</tr>
<tr>
<th>' . __('Discount 20%') . '</th>
<td>' . wc_price($order_total_discount) . '</td>
</tr>
<tr>
<th>' . __('Order total discounted') . '</th>
<td>' . wc_price($order_total_discounted) . '</td>
</tr>
</table>
</div><br>'; // HTML (end)
// Output CSS + HTML
echo $styles . $html_output;
}
这将输出如下内容:
代码进入您的活动子主题(或活动主题)的 function.php 文件。
已测试并有效。
To display it before Order details you can change the hook priority from 20
to 9
我以 20% 的折扣购买产品,然后在我的网站上以正常价格转售。 我想制作一封额外的电子邮件,当客户在我的网站上下订单时,必须将其发送到我自己的电子邮件地址。
我的问题: 如果可以制作一封新电子邮件,发送正常的付款详细信息,但也发送带有 20% 折扣的已付价格。
这对我以折扣价购买产品有很大帮助,这样我就可以将电子邮件发送给产品所有者。现在我必须计算正常价格的 20% 并将其发送给产品所有者。
有人有解决方案或提示吗?
感谢您的帮助。
您可以使用挂钩在 woocommerce_email_order_details
操作挂钩中的自定义函数,以“新订单”电子邮件通知为目标(发送给管理员),您将以这种方式添加这些详细信息:
add_action('woocommerce_email_order_details', 'new_order_custom_email_notification', 20, 4 );
function new_order_custom_email_notification( $order, $sent_to_admin, $plain_text, $email )
{
// Only for "New order" email notifications (admin)
if( $email->id != 'new_order' ) return;
$order_total = floatval($order->get_total());
$order_total_discount = $order_total * 0.2;
$order_total_discounted = $order_total - $order_total_discount;
// CSS style
$styles = '<style>
.discount-info table{width: 100%; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif;
color: #737373; border: 1px solid #e4e4e4; margin-bottom:8px;}
.discount-info table th, table.tracking-info td{text-align: left; border-top-width: 4px;
color: #737373; border: 1px solid #e4e4e4; padding: 12px; width:58%;}
.discount-info table td{text-align: left; border-top-width: 4px; color: #737373; border: 1px solid #e4e4e4; padding: 12px;}
</style>';
// HTML Structure
$html_output = '<h2>'.__('Reseller discount Information').'</h2>
<div class="discount-info">
<table cellspacing="0" cellpadding="6">
<tr>
<th>' . __('Order total') . '</th>
<td>' . wc_price($order_total) . '</td>
</tr>
<tr>
<th>' . __('Discount 20%') . '</th>
<td>' . wc_price($order_total_discount) . '</td>
</tr>
<tr>
<th>' . __('Order total discounted') . '</th>
<td>' . wc_price($order_total_discounted) . '</td>
</tr>
</table>
</div><br>'; // HTML (end)
// Output CSS + HTML
echo $styles . $html_output;
}
这将输出如下内容:
代码进入您的活动子主题(或活动主题)的 function.php 文件。
已测试并有效。
To display it before Order details you can change the hook priority from
20
to9