如何将自定义元数据添加到woocommerce中的订单项目

我正在使用此挂钩并添加自定义元数据,但它不起作用。您能否告诉我如何将自定义元数据添加到woocommerce的订单项中?如何将自定义元数据添加到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);

}

}

回答:

您需要使用woocommerce_add_order_item_meta钩因此您的代码将是这个样子的。

 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);

}

}

以上是 如何将自定义元数据添加到woocommerce中的订单项目 的全部内容, 来源链接: utcz.com/qa/261738.html

回到顶部