如何将自定义元数据添加到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_add_order_item_meta”钩子使用过时的数据结构和自3.2.5版本的功能已经过时了。替换为woocommerce_new_order_item。** 'add_action('woocommerce_add_order_item_meta','all_add_values_to_order_item_meta',10,3); ' 可以请你指导我如何工作没有任何错误 –