3
votes

I am having problems with my Wordpress installation, or WooCommerce to be more specific.

The client I've been working for the last couple of months, wants that every time a customer completes/pays an order, a custom email is sent to his email address, besides the standard order confirmation email.

In short: I need to send a custom email to the customer when the order is completed. How can I do that inside the functions.php?

I tried using various hooks and functions described in the official documentation, but couldn't figure it out.

The Wordpress version is 3.8.1, and WooCommerce is version is 2.0.20.

Thank You in advance.

3

3 Answers

4
votes

You can do that by using action called woocommerce_payment_complete;

$order = new WC_Order( $order_id );

function order_completed( $order_id ) {
    $order = new WC_Order( $order_id );
    $to_email = $order["billing_address"];
    $headers = 'From: Your Name <[email protected]>' . "\r\n";
    wp_mail($to_email, 'subject', 'message', $headers );

}

add_action( 'woocommerce_payment_complete', 'order_completed' );
3
votes

I solved the problem. I was using the wrong hook all the time. That's the main reason for the problems. The correct hook name was "woocommerce_thankyou". After I changed the functions to use this hook, everything went just right.

0
votes

I think you are not retrieving mail due to Three main reasons

  1. SMTP Plugin needed to be configured correclty if it is anabled
  2. Try PHP mail function as mail('[email protected]', 'My Subject', $message);
  3. Add priority to action being added as add_action( 'woocommerce_payment_complete', 'order_completed',1 );