Vikrant Kumar
Vikrant Kumar

Reputation: 1

How to add custom meta data to the Order Items in woocommerce

I am using this hook and adding custom meta data but it's not working. Can you please tell me how can i add custom meta data to the Order Items in woocommerce.

 add_action('woocommerce_new_order_item','all_add_values_to_order_item_meta',10,3);
    function all_add_values_to_order_item_meta($item_id,$values){
    if(!empty($values['tbb_right_sphere'])){
            $tbb_right_sphere=$values['tbb_right_sphere'];
    wc_add_order_item_meta($item_id,'od_right_sphere',$tbb_right_sphere);
        }
    }

Upvotes: 0

Views: 884

Answers (1)

dipmala
dipmala

Reputation: 2011

You need to use woocommerce_add_order_item_meta hook so your code will be looks like this.

 add_action('woocommerce_add_order_item_meta','all_add_values_to_order_item_meta',10,3); // add extra order metas

function all_add_values_to_order_item_meta($item_id,$values) { if(!empty($values['tbb_right_sphere'])) { $tbb_right_sphere=$values['tbb_right_sphere']; wc_add_order_item_meta($item_id,'od_right_sphere',$tbb_right_sphere); } }

Upvotes: 1

Related Questions