duanhui7329 2018-01-08 11:25
浏览 69
已采纳

WooCommerce自定义电子邮件的价格与客户不同

I am buying products with 20% discount and resell them for a normal price on my website. I want to make a extra email that has to be send to my own email address when a customer makes a order on my website.

My question: If it’s possible to make a new email that will send the normal payment details but also the payed price with the 20% discount on it.

This will help me a lot to buy the products with the discount price so I can send the email to the product owner. Right now I have to calculate the 20% of the normal price and send that to the product owner.

Does anyone have a solution or a tip?

Thanks for the help.

  • 写回答

1条回答 默认 最新

  • du94414 2018-01-08 13:03
    关注

    You could use a custom function hooked in woocommerce_email_order_details action hook, targeting "New Order" email notification (send to admin), where you will add those details this way:

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

    This will output something like:

    enter image description here

    Code goes in function.php file of your active child theme (or active theme).

    Tested and works.

    To display it before Order details you can change the hook priority from 20 to 9

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab