vendredi 17 juin 2016

Custom Email is not sending on Order complete in WooCommerce

I am facing a problem to send a custom email in WooCommerce.

Here is Error:

Fatal error: Cannot use object of type WC_Order as array in
/home/wp-content/themes/structure/functions.php on line 548

My client want to send a custom email when everytime customer order and pay, besides the standard order confirmation email.

Here is my code:

$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', 'This is custom email', $headers );

}

add_action( 'woocommerce_payment_complete', 'order_completed' )

I also tried "woocommerce_thankyou" hook instead of "woocommerce_payment_complete" but is still not working.

I use Wordpress version is 4.5.2 and WooCommerce version is 2.6.1.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire