WooCommerce custom mail different price than the customer

Refresh

April 2019

Views

78 time

1

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 answers

0

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