{"id":5137808,"date":"2014-07-28T19:24:24","date_gmt":"2014-07-28T19:24:24","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/storing-custom-cart-item-meta\/"},"modified":"2016-08-21T23:41:50","modified_gmt":"2016-08-21T23:41:50","slug":"storing-custom-cart-item-meta","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/storing-custom-cart-item-meta\/","title":{"rendered":"Storing custom cart item meta"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I&#8217;m trying to store a custom cart item value (unit of measure). The visitor selects from a custom dropdown while adding to cart. That value is then carried through the checkout process.<\/p>\n<p>This is the method I am currently using:<\/p>\n<pre><code>function _wpsc_add_to_cart_do_uom($product_id, $parameters, $this, $new_cart_item  )\n{\n\tif(isset($_REQUEST[&#039;wpsc_quantity_um&#039;]) &amp;&amp; $_REQUEST[&#039;wpsc_quantity_um&#039;] != &#039;&#039;)\n\t{\n\t\t$new_cart_item-&gt;update_meta(&#039;ordered_quantity_uom&#039;, esc_html(trim($_REQUEST[&#039;wpsc_quantity_um&#039;])));\n\t}\n}\nadd_action(&#039;wpsc_set_cart_item&#039;, &#039;_wpsc_add_to_cart_do_uom&#039;, 1, 4);<\/code><\/pre>\n<p>It works as expected with one exception: If the user adds to cart and then logs in to a WP account, the custom meta value is lost. The cart item itself carries over to the user&#8217;s cart but without the meta value.<\/p>\n<p>Is $new_cart_item-&gt;update_meta the right approach or is there a better way to do this? Do I maybe have to tie into another filter to transfer the item meta values over to the user&#8217;s cart at login? I&#8217;ve been digging through the core files trying to come up with something, but no luck yet.<\/p>\n<p>Thanks,<\/p>\n<p>Tim<\/p>\n<p>https:\/\/wordpress.org\/plugins\/wp-e-commerce\/<\/p>\n","protected":false},"template":"","class_list":["post-5137808","topic","type-topic","status-closed","hentry","topic-tag-cart","topic-tag-users"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5137808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5137808\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5137808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}