Snippet to Log “Payment Failed” in Syslog [closed]

You can use the woocommerce_order_status_changed action to find a failed order transition, and syslog to write your log, assuming the function is not disabled in your PHP configuration.

add_action( 'woocommerce_order_status_changed', function ( $order_id, $old_status, $new_status ) {
    if ( 'failed' !== $new_status ) {
        return;
    }

    $order = wc_get_order( $order_id );
    if ( ! $order ) {
        return;
    }

    $ip = $order->get_customer_ip_address();

    openlog( 'wordpress', LOG_PID | LOG_ODELAY, LOG_LOCAL0 );
    syslog( LOG_WARNING, "woocommerce.payment_failed ip=$ip order=$order_id" );
    closelog();
}, 10, 3 );

You should get something like this in your syslog:

Sep 18 14:25 host wordpress[12345]: woocommerce.payment_failed ip=1.2.3.4 order=1234

Hope this helps!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)