title: Woocommerce - Remove all old cart items if logged in during checkout
body: <p><br>
  I'm trying to delete all old cart items if the user logs in during checkout.<Br><br>
  For example:<Br>
  a. User adds 2 items some days ago<br></p>
  
  <blockquote>
    <p>&nbsp;&nbsp;&nbsp; - Cap<br> &nbsp;&nbsp;&nbsp; - Ball<br></p>
  </blockquote>
  
  <p>b. Then he logged out and today he adds some items in cart to purchase.<br></p>
  
  <blockquote>
    <p>&nbsp;&nbsp;&nbsp; - Hoodie<br> &nbsp;&nbsp;&nbsp; - Mobile Phone<br></p>
  </blockquote>
  
  <p>He is asked to login during checkout and the cart shows 4 products.<br></p>
  
  <blockquote>
    <p>&nbsp;&nbsp;&nbsp; - Cap<br> &nbsp;&nbsp;&nbsp; - Ball<br> 
    &nbsp;&nbsp;&nbsp; - Hoodie<br> &nbsp;&nbsp;&nbsp; - Mobile Phone<br></p>
  </blockquote>
  
  <p>How to only show the two latest product and deleted the old ones.</p>
  
  <blockquote>
    <p>&nbsp;&nbsp;&nbsp; - Hoodie<br> &nbsp;&nbsp;&nbsp; - Mobile Phone<br></p>
  </blockquote>
  
  <p><br><br>
  I added the following code to my <code>functions.php</code> but it deletes all previously added products form all the pages. </p>
  
  <pre><code>function clear_persistent_cart_after_login( $user_login, $user ) {
      $blog_id = get_current_blog_id();
  
      if ( metadata_exists( 'user', $user-&gt;ID, '_woocommerce_persistent_cart_' . $blog_id ) ) {
          delete_user_meta( $user-&gt;ID, '_woocommerce_persistent_cart_' . $blog_id );
      }
  }
  add_action('wp_login', 'clear_persistent_cart_after_login', 10, 2);
  </code></pre>
  
  <p>I only want them to be deleted when logged in from checkout page. I also tried using permalink but it didn't work.
  <br> Please Help. </p>