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 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。