Remove MetaData from OrderItem
-
This is how I set custom meta data for a product which gets added to basket:
add_action( 'woocommerce_checkout_create_order_line_item', 'save_cart_item_custom_meta_as_order_item_meta', 10, 4 ); function save_cart_item_custom_meta_as_order_item_meta( $item, $cart_item_key, $values, $order ) { $meta_key1 = 'Product 1'; if ( isset($values['add_size']) && isset($values['add_size'][$meta_key1]) ) { $item->update_meta_data( $meta_key1, $values['add_size'][$meta_key1] ); }I need to remove this custom meta data after a purchase (‘woocommerce_thankyou’) but first I need to use it to add a product to the order.
add_action('woocommerce_thankyou', 'add_order_gift_note', 10, 1); function add_order_gift_note( $order_id ) { foreach ( $order->get_items() as $item_id => $item ) { $extras = $item->get_formatted_meta_data('_', true); foreach($extras as $extra){ $mini_id = $extra->value; $order->add_product( wc_get_product($mini_id), $product_quantity); // Add Minis } // Now hide or remove the meta data.Either removing it or hiding some meta data from the order at this point is the desired solution.
I don’t want the IDs to show in the orders: https://imgur.com/a/taBHRMh
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Remove MetaData from OrderItem’ is closed to new replies.