gpt4 book ai didi

Get the order fee item details in Woocommerce 3(在WooCommerce 3中获取订单费项目详细信息)

转载 作者:bug小助手 更新时间:2023-10-28 20:50:39 26 4
gpt4 key购买 nike



I try to get the name of the fee attached to my order in Woocommerce, I get an array but I don't know how to get the name.

我尝试在WooCommerce中获取附加到我的订单的费用的名称,我得到了一个数组,但我不知道如何获得名称。



I tried with function get_name () but it does not work.

我尝试使用函数GET_NAME(),但它不起作用。



$the_order->get_items( array( 'line_item', 'fee', 'shipping' ) );


Raw data output:

原始数据输出:



[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
(
)

)

)

更多回答
优秀答案推荐

To access and to use properties on Order Fee items you need to use the WC_Order_Item_Fee methods using first a foreach loop this way:

要访问和使用Order Feed项的属性,您需要使用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();
}


Tested and works

测试和工作


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com