title: Redirect unlogged users to My account if accessing checkout in WooCommerce
body: <p>My desired sequence would be:</p>
  <p>User Checkout &gt; Check login &gt;</p>
  <p>Proceed to checkout if logged in.
  Redirect to login/register page if not logged in &gt; proceed to the checkout page.
  I have added below code in my active theme's function.php file but still having same problem</p>
  <pre><code>add_action( 'template_redirect', 'check_if_logged_in' );
  function check_if_logged_in() {
      $pageid = 817; // your checkout page id
  
      if ( ! is_user_logged_in() &amp;&amp; is_page( $pageid ) ) {
          $url = add_query_arg(
              'redirect_to',
              get_permalink( $pageid ),
              site_url( '/my-account/' ) // your my acount url
          );
  
          wp_redirect( $url );
          exit;
      }
  }
  </code></pre>
  <p>What I am doing wrong? Thanks in advance everyone.</p>