我试着在Woocommerce中获得我的订单所附费用的名称,我得到一个阵列,但我不知道如何得到这个名字。
我尝试使用函数get_name ()
,但它不起作用。
$the_order->get_items( array( 'line_item', 'fee', 'shipping' ) );
原始数据输出:
[137] => WC_Order_Item_Fee Object
(
[extra_data:protected] => Array
(
[tax_class] =>
[tax_status] => taxable
[amount] =>
[total] =>
[total_tax] =>
[taxes] => Array
(
[total] => Array
(
)
)
)
[data:protected] => Array
(
[order_id] => 7795
[name] => Frais de réservation
[tax_class] => 0
[tax_status] => taxable
[amount] =>
[total] => 35
[total_tax] => 0
[taxes] => Array
(
[total] => Array
(
)
)
)
答案 0 :(得分:4)
要访问和使用订购费项目的属性,您需要使用WC_Order_Item_Fee方法首先使用foreach循环:
// (optional if not defined) An instance of the WC_Order object
$the_order = wc_get_order( $order_id );
// Iterating through order fee items ONLY
foreach( $the_order->get_items('fee') as $item_id => $item_fee ){
// The fee name
$fee_name = $item_fee->get_name();
// The fee total amount
$fee_total = $item_fee->get_total();
// The fee total tax amount
$fee_total_tax = $item_fee->get_total_tax();
}
经过测试和工作