title: How save product id of 1st item added to cart in woocommerce for a visitor in empty cart page?
body: <p>I am trying to display the product id which is added to cart at first in empty cart page(<code>cart-empty.php</code>). Can anyone please help me with any solution.</p>
  
  <p>Here is my code I have tried for <code>cart-totals.php</code> page..which save both product slug and its parent slug which is added at last to the cart.</p>
  
  <pre><code>$items = $woocommerce-&gt;cart-&gt;get_cart();
              foreach($_SESSION['items'] as $item =&gt; $values) { 
                  $_product = $values['data']-&gt;post; 
                  $cartproductid = $_product-&gt;ID;
              }
              $product_cats = wp_get_post_terms( $cartproductid, 'product_cat' );
              $url=$product_cats[0]-&gt;slug;
              $parenturl=$product_cats[0]-&gt;parent;
  
    $terms = get_the_terms($cartproductid, "product_cat");
    $cat = get_term_by("id", $parenturl, "product_cat");
    $newurl = $cat-&gt;slug;
  </code></pre>