0

I want to create an custom function that can send an custom order email to an chosen supplier (in the checkout form). But when i try to get the data from the checkout in the email, the checkout form did not sent the order. I could also not complete the order.

Hopefully someone could help me, and tell me what is wrong in my code.

Code:

// Triggers for this email
add_action("woocommerce_checkout_order_processed", "my_awesome_publication_notification");

function my_awesome_publication_notification($post_id) {
    global $woocommerce;

    $post = get_post($post_id);
    $checkout = $woocommerce->checkout();
    $order = new WC_Order( $order_id );
    $author = get_userdata($post->post_author);
    $title = get_the_title();

    $author_email = 'info@domain.nl';
    $email_subject = 'New order recieved';
    $site_title = get_bloginfo('name');
    $customer_address = $woocommerce->customer->get_adress();
    $customer_address_2 = $woocommerce->customer->get_adress_2();
    $customer_postcode = $woocommerce->customer->get_postcode();
    $customer_city = $woocommerce->customer->get_city();
    $customer_country = $woocommerce->customer->get_country();

    ob_start();

    include("email_header.php");

    ?>

    <p>
        Hi, <?php //echo $author->display_name ?>. I've just published one of your articles 
        (<?php //echo $post->post_title ?>) on <?php echo $site_title; ?>!
    </p>
    <h2>Order informatie</h2>
    <strong>Adres:</strong><br /> <?php echo $customer_address; ?> <br />
    <strong>Adres (extra):</strong><br /> <?php echo $customer_address_2; ?> <br />
    <strong>Postcode:</strong><br /> <?php echo $customer_postcode; ?> <br />
    <strong>Plaatsnaam:</strong><br /> <?php echo $customer_city; ?> <br />
    <strong>Land:</strong><br /> <?php echo $customer_country; ?>

 </p>




    <?php

    include("email_footer.php");


    $message = ob_get_contents();

    ob_end_clean();


    wp_mail($author_email, $email_subject, $message, $headers);

}

add_filter('wp_mail_content_type','set_content_type');

function set_content_type($content_type){
return 'text/html';
}
  • This link would help you to know how to create custom email notification in woocommerce. – Ravinder Kumar Nov 8 '13 at 17:26
  • But this plugin does not tell me how i get some custom information, from the checkout in my email – rschouwenaar Nov 10 '13 at 12:02
  • I would suggest reading this tutorial. – helgatheviking Oct 7 '14 at 11:34
-3

After some searching and testing i found the solution. It's not very difficult!

Check the code on my blog

I hope i've helped you guys to!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.