的
更新:
</强>
自Woocommerce第3版以来,您的代码已经过时了。请参阅:
所以你的代码应该是:
$skus = $item_quantities = $line_item_totals = $items_meta_data = array();
// Loop though order items
foreach( $order->get_items() as $item_id => $item){
$product_id = $item->get_product_id();
$product = $item->get_product();
$item_quantities[] = $item->get_quantity();
$line_item_totals[] = $item->get_total();
$skus[] = $product->get_sku();
$items_meta_data[] = $item->get_meta_data();
}
// Product details for sending as one line to an external service
foreach ($skus as $key => $value){
$data .= “&product[“.$key.”]=”.$value.””;
$data .= “& product_kol[“.$key.”]=”.$item_quantities[$key].””;
$data .= “& product_price[“.$key.”]=”.$line_item_totals[$key].””;
if( isset($product_mod[$key]) ) {
$data .= “&product_mod[“.$key.”]=”.$product_mod[$key].””;
}
}
</code>
它应该更好,但是
$product_mod
没有定义和
$item->get_meta_data()
未使用。
现在
的
获取一些自定义元数据
</强>
,如果你的定制
的
元键
</强>
是
Custom thing
,你会用:
$custom_thing = $item->get_meta(‘Custom thing’);
</code>
这应该包含在订单项的foreach循环中,经过测试和工作。
其他一些事情:
要获得NON折扣订单项总计:
$item->get_subtotal();
要获得折扣订单项总计:
$item->get_total();
要获得产品价格(单位):
$product->get-price();