All payment methods are sending email to admin and customer after completed order. I have custom payment method via plugin with a bank, that is on success returning empty cart, new order in list and everything else works fine, but it doesn't send emails. Because mail function doesn't exist inside plugin. On successful payment I need to send exactly the same email from processing order template as with other payment methods. I know when to trigger function, but do not know what function to call.
<?php
class My_Class extends WC_Payment_Gateway {
...
function __construct() {
...
if ( is_admin() ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
if( isset($_POST['oid']) && isset($_POST['Response']) )
$this->process_respond($_POST['oid'], $_POST['Response']);
}
public function process_respond($response_order_id, $result){
global $woocommerce;
$customer_order = new WC_Order( $response_order_id );
$error_msg = "Error in transaction";
if ( $result == "Approved" ) {
My_Class::extend($customer_order);
...
// I need to trigger function here
wp_mail(...)
die();
} else {
...
}
}
}
All payment methods are sending email to admin and customer after completed order. I have custom payment method via plugin with a bank, that is on success returning empty cart, new order in list and everything else works fine, but it doesn't send emails. Because mail function doesn't exist inside plugin. On successful payment I need to send exactly the same email from processing order template as with other payment methods. I know when to trigger function, but do not know what function to call.
<?php
class My_Class extends WC_Payment_Gateway {
...
function __construct() {
...
if ( is_admin() ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
if( isset($_POST['oid']) && isset($_POST['Response']) )
$this->process_respond($_POST['oid'], $_POST['Response']);
}
public function process_respond($response_order_id, $result){
global $woocommerce;
$customer_order = new WC_Order( $response_order_id );
$error_msg = "Error in transaction";
if ( $result == "Approved" ) {
My_Class::extend($customer_order);
...
// I need to trigger function here
wp_mail(...)
die();
} else {
...
}
}
}
Share
Improve this question
asked Jul 19, 2017 at 14:27
Nemanja ĐatkovNemanja Đatkov
11 silver badge4 bronze badges
1 Answer
Reset to default 0You can do it very easily by using his mail class. you can extend that class as well. Here is the code which should work with your class code. if it did not work than you need to extend the woocommerce email class same like you did for your custom payment gateway.
$mailer = WC()->mailer();
$mails = $mailer->get_emails();
if ( ! empty( $mails ) ) {
foreach ( $mails as $mail ) {
if ( $mail->id == 'new_order' || $mail->id == 'customer_processing_order' ){
$mail->trigger( $order->id );
}
}
}