title: Update basket custom attribute on basket/cart page WooCommerce Product Add-ons
body: <p>I have been trying to make it so that I can update a custom field(per product) I have added on the basket/cart page using <strong>WooCommerce Product Add-ons</strong>.</p>
  <p>I did get a method working as a test, but it is really a good solution, and most of it is a test/bad code. It also only works the second time for some reason - as if the cache is breaking it!
  It will be changed via a textarea, but I have set a value for now to see if I can get it to work.</p>
  <p>So, to clarify, on submit first time, nothing happens, secound time it updates the product, however it now doesn't update the attribute, it updates quantity etc(when I add a value in the code) but not the attribute.</p>
  <p>I have set it to delete the product afterwards but it looses the attribute when I delete it so I have left the duplication in there for now until I fix the double update required for it to update the page!</p>
  <p>Is there anything anyone can see that will point me in the direction of a quicker fix? Greatly apprecaite any help!!!</p>
  <p>As you can see from the commenting out I have been trying a few ways, but keep failing!!</p>
  <pre><code>&lt;?php
  if ( ! empty( $_POST['update_cart'] ) )  {
      $cart_totals = isset( $_POST['cart'] ) ? $_POST['cart'] : '';
      if ( sizeof( $woocommerce-&gt;cart-&gt;get_cart() ) &gt; 0 ) {
          foreach ( $woocommerce-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values ) {
              if ( isset( $cart_totals[ $cart_item_key ]['addons'] ) ) {
                  WC()-&gt;cart-&gt;remove_cart_item($cart_item_key);
                  #print_r($woocommerce-&gt;cart-&gt;cart_contents[ $cart_item_key ]['addons']);                    
                  #$cart_item['addons'] = array('name' =&gt; 'Add your message', 'value' =&gt; 'testing the message box', 'price' =&gt; 0, 'field_name' =&gt; $cart_item['product_id'].'-add-your-message-1', 'field_type' =&gt; 'custom_textarea', 'price_type' =&gt; 'quantity_based' );
                  $data = array('name' =&gt; 'Add your message', 'value' =&gt; 'testing the message box', 'price' =&gt; 0, 'field_name' =&gt; $cart_item['product_id'].'-add-your-message-1', 'field_type' =&gt; 'custom_textarea', 'price_type' =&gt; 'quantity_based' );
                  #WC()-&gt;cart-&gt;add_to_cart($cart_item['product_id'], $cart_item['quantity'], $cart_item['variation_id'], $cart_item['addons']);
                  WC()-&gt;cart-&gt;add_to_cart($cart_item['product_id'], $cart_item['quantity'], $cart_item['variation_id'], $cart_item['addons']);
                  #$woocommerce-&gt;cart-&gt;cart_contents[$cart_item_key]['addons'][0]['value'] = 'test';
                  $woocommerce-&gt;cart-&gt;cart_contents[$cart_item]['addons'] = $data;
                  
              }
          }
      }
  }
  </code></pre>
  <p>EDIT:
  The below is updating the message box per item, which is great and exactly what was needed, just trying to get the session to accept the update. The cart is a multipage cart as that is what was requested, so when you go to the next page/checkout page you can see it has reverted back to the original message and you can see it in the cart session. Also, if you just refresh the page it reverts back(after you have already updated the page).</p>
  <p>I have tried to edit via WC()-&gt;session-&gt;set but I think I am setting the wrong bit! I get some of the session set, but it doesn't set the correct entry!</p>
  <pre><code>add_action('woocommerce_update_cart_action_cart_updated', function ($cartUpdated) {
      // loop through cart items, passing the $item array by reference, so it can be updated
      foreach (WC()-&gt;cart-&gt;cart_contents as $key =&gt; &amp;$item) {
          // set the values of the addons array as required
          $test = $_POST['cart'][$key]['addons'];
          $item['addons'][0]['value'] = $test;
          print_r(WC()-&gt;session-&gt;get( 'cart'));
      }
  });
  </code></pre>
  <p>EDIT - WORKING CODE:
  Thank you to @benJ for the solution, very helpful! The session needed to be set, but not the way I thought I had to do it!</p>
  <pre><code>// hook on woocommerce_update_cart_action_cart_updated
  add_action('woocommerce_update_cart_action_cart_updated', function ($cartUpdated) {
      // loop through cart items, passing the $item array by reference, so it can be updated
      foreach (WC()-&gt;cart-&gt;cart_contents as $key =&gt; &amp;$item) {
          // set the values of the addons array as required
          $addon = $_POST['cart'][$key]['addons'];
          $item['addons'][0]['value'] = $addon;
          // set the session
          WC()-&gt;cart-&gt;set_session();
      }
  });
  </code></pre>
  <p>Cheers
  Iskander</p>