Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4

Updated

Since Woocommerce version 3, woocommerce_checkout_create_order_line_item action hook now replace outdated woocommerce_add_order_item_meta hook in a much better way using the new introduced CRUD getters and setters methods:

// Save custom data to order item meta data
add_action( 'woocommerce_checkout_create_order_line_item', 'tshirt_order_meta_handler', 20, 4 );
function tshirt_order_meta_handler( $item, $cart_item_key, $values, $order ) {
    $custom_designer = WC()->session->get( $cart_item_key.'_designer' );
    if( ! empty($custom_designer) ) {
        $item->update_meta_data( 'custom_designer', $custom_designer );
    }
}

Code goes in function.php file of your active child theme (or active theme). It should works.

See this related thread:
Woocommerce: Which hook to replace deprecated “woocommerce_add_order_item_meta”

Leave a Comment