Oh CRUD! Custom Meta to order from cart
-
Short story is I have been trying to wrap my head around it, and honestly its been a bit much for my tiny little brain. I thank Claudio Sanches for clarifying some of the things that haven’t sunk in about both the new methods and the code I am trying to update – – the original function used to add the custom fields as meta to the order item with wc_add_order_item_meta and was hooked on woocommerce_add_order_item_meta (deprecated in 3.0). Now the code is hooked via the woocommerce_checkout_create_order_line_item and using “add_meta”
ecard_order_meta_handler( $item_id, $values, $cart_item_key ) { if( isset( $values['ecard_greeting'] ) ) { add_meta( $item_id, 'ecard_greeting', $values['ecard_greeting'] ); }
and that seems to work (or at least its not throwing any errors) however it is not saving the data to the order using the same save function as before which is using $cart_item_data with the hook woocommerce_add_cart_item_data:
save_card_order_info( $cart_item_data, $product_id ) { $extraFields = array( 'ecard_greeting', 'etcetera'); foreach($extraFields as $field) { if( isset( $_REQUEST[$field] ) ) { $cart_item_data[ $field ] = $_REQUEST[$field]; $cart_item_data['unique_key'] = md5( microtime().rand() ); } } return $cart_item_data;
So what am I missing?
- The topic ‘Oh CRUD! Custom Meta to order from cart’ is closed to new replies.