title: Clear cart Woocommerce when close browser
body: <p>i try to clean the cart when the browser is close. In this time i have the next code, it works whe you go to main page</p>
  
  <pre><code>/*empty cart if user come to homepage*/
  add_action( 'init', 'woocommerce_clear_cart_url' );
  function woocommerce_clear_cart_url() {
  global $woocommerce;
  
  if ($_SERVER['REQUEST_URI'] === '/') { 
  $woocommerce-&gt;cart-&gt;empty_cart(); 
  }
  }
  </code></pre>
  
  <p>how to change this code when browser is close clean the cart</p>