WooCommerce 将项目添加到订单 [英] WooCommerce Add item to Order
问题描述
我正在尝试将一个项目添加到现有订单,但它无法正常工作...每次我执行下面的代码时,广告和空项目,有什么帮助吗?
I'm trying to add an item to an existent order but it's not working properly... Everytime I execute the code below it ads and empty item, any help?
woocommerce_add_order_item($Novo_PostId, $item);
$item 是 var 女巫从我的另一个订单中接收项目本身,我已经放了一个 print_r($item) 并且它看起来没问题.
$item is the var witch receives the item itself from another order I have, I've put a print_r($item) and it appears to be ok.
推荐答案
在您使用 woocommerce_add_order_item
创建项目后,您必须使用 woocommerce_add_order_item_meta()
设置元数据,请参阅:http://docs.woothemes.com/wc-apidocs/function-woocommerce_add_order_item_meta.html
After you create your item with woocommerce_add_order_item
you have to set the meta data with woocommerce_add_order_item_meta()
, see: http://docs.woothemes.com/wc-apidocs/function-woocommerce_add_order_item_meta.html
类似于:
$item_id = woocommerce_add_order_item( $order_id, array(
'order_item_name' => '',
'order_item_type' => 'line_item'
) );
if ( $item_id ) {
$foreach($metavalues as $key=>$value)
{
woocommerce_add_order_item_meta( $item_id,$key,$value);
}
}
这篇关于WooCommerce 将项目添加到订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!