• I want to be able to send an email to shop admin when payment is declined/not successful. I’ve looked at http://docs.woothemes.com/wc-apidocs/class-WC_Order.html and have tried several methods of this class. Example usage in functions.php:

    add_action( 'woocommerce_checkout_order_processed', 'send_order_xyg');
    function send_order_xyg($order_id) {
        $order = new WC_Order( $order_id );
        $order_status           = $order->get_status(); //returns 'pending' even on successfull payment
        $order->needs_payment(); // always returns true, even on successful payment
    
    }

    I can’t figure out the timing of when the order is changed from ‘pending’ to ‘processing.’ If I make a successful order, It seems it’s changed to ‘processing’ right away, but when I hook into woocommerce_checkout_order_processed it’s always ‘pending’ for $order_status and $order->needs_payment() returns true, when you’d think it would be opposite.

    What hook should I use to immediately check that payment on each new order isn’t successful or the order isn’t processing?

    https://wordpress.org/plugins/woocommerce/

The topic ‘Check for payment error immediately after payment attempt’ is closed to new replies.