Send an email to a customer on order at WooCommerce

I'm having trouble installing Wordpress or WooCommerce to be more specific.

The client I’ve been working with for the last couple of months wants every time the client completes / pays for the order, a user email address is sent to his email address, in addition to the standard order confirmation email.

In short: I need to send a registered letter to the customer when the order is completed. How can I do this inside functions.php function?

I tried using various hooks and functions described in the official documentation, but could not understand.

Wordpress version is 3.8.1, and WooCommerce is version 2.0.20.

Thanks in advance.

+3
source share
3 answers

You can do this using an 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 <your@email.com>' . "\r\n";
    wp_mail($to_email, 'subject', 'message', $headers );

}

add_action( 'woocommerce_payment_complete', 'order_completed' );
+4
source

I solved the problem. I constantly used the wrong hook. This is the main cause of the problems. The correct hook name was " woocommerce_thankyou ". After I changed the functions to use this hook, everything went right.

+3
source

, - .

  • SMTP ,
  • PHP mail('caffeinated@example.com', 'My Subject', $message);
  • , add_action( 'woocommerce_payment_complete', 'order_completed',1 );
0

All Articles