title: WordPress bring session data from product page to cart page in custom plugin?
body: <p>I have product page listed all product have add button when some one click it should pick up the product related data in session array bring into cart page and show in cart page like woocommmerce does.</p>
  
  <p>This is custom independent mini plugin. </p>
  
  <p>my code and output is bellow.</p>
  
  <p><strong>2 custom table:</strong></p>
  
  <p>wp_productlist</p>
  
  <p>wp_product_category.</p>
  
  <p><strong>IN COMMENT i HAVE EXPLAIN EVERYTHING ABOUT CODE:</strong></p>
  
  <pre><code>  &lt;?php
    global $wpdb;
   $result = $wpdb-&gt;get_results ( "SELECT * from wp_product_category  "); //Select all data from wp_product_category which is item_id and category columns.
    //main loop
   foreach ( $result as $print){ // loop the wp_product_category table.
     $cat = $print-&gt;item_id; ?&gt; //pick item_id store in $cat variable.
     &lt;button class="collapsible"&gt;&lt;?=$print-&gt;category?&gt;&lt;/button&gt;
     //show the category name in accordion through loop. 
   &lt;div class="content"&gt;
   &lt;table border="1"&gt; // table is start here.
    &lt;tr&gt;
      &lt;th&gt;Item_ID&lt;/th&gt;    
      &lt;th&gt;Item Description&lt;/th&gt;   // three columns of table
      &lt;th&gt;Packing Size&lt;/th&gt;   
     &lt;th&gt;Cart&lt;/th&gt; //Custom column for add to cart button.
    &lt;/tr&gt;
    &lt;?php
    $result1 = $wpdb-&gt;get_results ( "SELECT * FROM wp_productlist where 
    category_id = $cat "); //Select everthing from wp_productlist tabl where category_id = $cat. (above $cat= item_id).  
     foreach ( $result1 as $print1 )   { //Nested loop to show data under category in tables.
  
      echo '&lt;tr&gt;';
        echo '&lt;td&gt;'. $print1-&gt;item_id.'&lt;/td&gt;';
        echo '&lt;td&gt;'. $print1-&gt;Item_Description.'&lt;/td&gt;';// showing data from wp_productlist
        echo '&lt;td&gt;'. $print1-&gt;Packing.'&lt;/td&gt;';
       echo '&lt;td&gt; &lt;form method="post"&gt; &lt;input type="submit" name="add" href="$print1-&gt;item_id" value="ADD"&gt;&lt;/form&gt; &lt;/td&gt;'; // add to cart button its not taking id to cart page.
      echo '&lt;/tr&gt;';  
   }  
    echo '&lt;/tr&gt; ';
     ?&gt;            
  
  &lt;/table&gt; //table end here
  &lt;/div&gt;
   &lt;?php } 
      if (isset($_POST['add'])) // when press add to cart button.
       {
         //Store the related row data in session array which is store but the last one row of the table not the one I click. 
          $_SESSION['cart_items'] = array(
  
              'oid' =&gt; $print1-&gt;item_id,
              'des' =&gt; $print1-&gt;Item_Description,
              'pack' =&gt;  $print1-&gt;Packing
           ) ;
  
           $cart_items = ! empty( $_SESSION['cart_items'] ) ? // show data for testing.
           $_SESSION['cart_items'] : false;
  
           print_r($cart_items);
       }
    ?&gt;
  </code></pre>
  
  <p><strong>OUT PUT OF PRODUCT LIST PAGE</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/2XsIo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2XsIo.png" alt="enter image description here"></a></p>
  
  <p>Now when some one press the add button I want redirection from the product listed page with the data and want to show in the cart page like woocommerce doing it but my plugin is not integrated with woocommerce and it is independent custom plugin.</p>
  
  <p>Cart page code is bellow in cart page it show me the session data but the last row in my table I want to show the row just I click on the add to cart button as show the output above</p>
  
  <p>after clicking the add to cart button in table it is not redirecting to cart page please redirect it.</p>
  
  <p>show the data like woocommerce cart page with my row of the table </p>
  
  <pre><code>   &lt;?php
      $cart_items = ! empty( $_SESSION['cart_items'] ) ? // accessing the data in the cart page 
      $_SESSION['cart_items'] : false;
      print_r($cart_items);
       ?&gt; 
  </code></pre>
  
  <p>I want this data in one row in this cart page like woocommerce doing it well.</p>
  
  <blockquote>
    <p>OUT PUT OF CART PAGE BUT I AM GETTING WRONG DATA NO MATTER WHAT
    PRODUCT SOME ONE SELECT IT WILL PICK UP THE LAST ITEM IN THE TABLE AND
    SHOW ME IN THE CART PAGE IN ONE ROW TABLE OPTION TO DELETE ITEM OR
    PROCEED TO CHECK OUT.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/QcQxe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QcQxe.png" alt="enter image description here"></a></p>