WooCommerce – template_redirect if is_checkout AND order has been paid?

I figured it out. woocommerce_payment_succesful_result guided me in the right direction, although it wasn’t the final answer. function is_wc_endpoint_url() is really useful here, it checks where woocommerce is about to redirect next.

// redirect empty checkouts and completed orders.
add_action( 'template_redirect', 'myfunction' );
function myfunction() {

    if( is_wc_endpoint_url( 'order-received' ) && isset( $_GET['key'] ) ) {
        wp_redirect('www.myurl.com'); // go to custom page if order has been received
        exit;
    }

    if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() ) {
       wp_safe_redirect( home_url() ); // if trying to access checkout with empty cart go back
       exit;
    }  
}