Storing custom cart item meta
-
Hello,
I’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.
This is the method I am currently using:
function _wpsc_add_to_cart_do_uom($product_id, $parameters, $this, $new_cart_item ) { if(isset($_REQUEST['wpsc_quantity_um']) && $_REQUEST['wpsc_quantity_um'] != '') { $new_cart_item->update_meta('ordered_quantity_uom', esc_html(trim($_REQUEST['wpsc_quantity_um']))); } } add_action('wpsc_set_cart_item', '_wpsc_add_to_cart_do_uom', 1, 4);
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’s cart but without the meta value.
Is $new_cart_item->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’s cart at login? I’ve been digging through the core files trying to come up with something, but no luck yet.
Thanks,
Tim
- The topic ‘Storing custom cart item meta’ is closed to new replies.