Woocommerce: Which hook to replace deprecated "woocommerce_add_order_item_meta"

user3339988 picture user3339988 · Apr 16, 2015 · Viewed 18k times · Source

Need to add custom meta to order items. Googled it and most articles says to use "woocommerce_add_order_item_meta" hook. This hook is deprecated in the newest version 2.3.7. Someone, please tell me which hook to use instead.

http://docs.woothemes.com/wc-apidocs/function-woocommerce_add_order_item_meta.html

Answer

helgatheviking picture helgatheviking · Apr 16, 2015

If you look at wc-deprecated-functions.php you will see

/**
 * @deprecated
 */
function woocommerce_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
    return wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique );
}

Basically, the function was renamed to wc_add_order_item_meta(), so if you need the function then use that. The action hook was not renamed and remains in class-wc-checkout.php as:

// Allow plugins to add order item meta
do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );