Assigning email address to each line item in order
-
Hi,
I have a membership site where I’m trying to assign different email addresses as the item meta for each item added to the cart.
I’m using a combination of the following actions/filters along the lines of what’s described here:
woocommerce_add_cart_item_data woocommerce_get_cart_item_from_session woocommerce_get_item_data woocommerce_checkout_create_order_line_item
Assigning the email address/user info works great as long as I don’t attempt to add a 2nd product (i.e. increment the quantity by selecting the same product twice).
To (try to) allow having one line item per item of the same product, I use
woocommerce_add_to_cart
and the linked code.This code splits out the individual product line items (same product). However, it seems – to me – like the ‘woocommerce_get_cart_item_from_session’ filter may be overwriting the content of the
_e20r_item_owner
key whenever it’s called against the same product ID.I’ve tried using a base64 hash of the email address and used a different email address each time I add the same product ID to the cart. The result is that the most recently used email hash is the one being shown in the resulting
$data
array output from thewoocommerce_get_item_data
filter.This is true for all of the line items representing an added instance of the product with ID # 1407 in the cart.
How can I assign and persist a different item meta data value every time the same product id is added to the cart (and not have it appear to overwrite the previously added items with the same ID)?
- The topic ‘Assigning email address to each line item in order’ is closed to new replies.