The following should suffice. It will redirect to your custom URL only if the order has not failed.
add_action( 'woocommerce_thankyou', 'ii_redirect_thankyou');
function ii_redirect_thankyou( $order_id ){
$customer_orders = get_posts( array(
'numberposts' => 2, // getting 2 as by the time this purchase has happened the count will be 1.
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => 'shop_order', // WC orders post type
'post_status' => 'wc-completed', // Only orders with "completed" status
'fields' => 'ids', // Return Ids "completed"
) );
if ( count($customer_orders) > 1 ) {
$order = wc_get_order( $order_id );
$url="http://example.com";
// double check this order has gone through okay and then redirect them
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}
}
function woocommerce_redirect_after_checkout(){
global $wp;
if (is_checkout()&&!empty($wp->query_vars[‘order-completed’])){
$redirect_url=”https://example.com”;
wp_redirect($rediect_url);
exit;
}
}