login or register then access woocommerce website

You can use “template_redirect” action to check if the current user is logged in or not then redirect the user to my-account page if not.

add_action( 'template_redirect', function() {
    $url_parts = array_filter( explode( "https://wordpress.stackexchange.com/", $_SERVER['REQUEST_URI'] ), 'strlen' );
    if ( ! is_user_logged_in() && ( end( $url_parts ) != 'my-account' ) ) {
        wp_redirect( home_url( '/my-account' ) );
        die();
    }
});

error code: 523