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.

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" ) {


        // I need to trigger function here


    } else {



You 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 );                    
  • Thank you very much! I will extend WC_Email class. First solution doesn't work. – Nemanja Đatkov Aug 3 '17 at 7:58
  • You mean to say mentioned code is not working for you? – Aki Aug 3 '17 at 8:26
  • Yeah, I mean no, it's not working. But I think problem is somewhere else. Guess your method will work in normal circumstances. – Nemanja Đatkov Aug 4 '17 at 11:45
  • Share fttp or something or can i see what else u did in the cod? – Aki Aug 4 '17 at 19:02
  • Thanks, but admin says no no no. It's on local network, so still no public access while it's in production. Thanks anyway. – Nemanja Đatkov Aug 8 '17 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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