Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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';
}
share|improve this question
    
This link would help you to know how to create custom email notification in woocommerce. –  Ravs Nov 8 '13 at 17:26
    
Thanks! I´m gonna take a look! –  rschouwenaar Nov 10 '13 at 11:58
    
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 at 11:34

1 Answer 1

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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