gpt4 book ai didi

php - 获取 Woocommerce 3 中的订单费用项目详细信息

转载 作者:行者123 更新时间:2023-12-04 16:03:09 25 4
gpt4 key购买 nike

我尝试在 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
(
)

)

)

最佳答案

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

测试和工作

关于php - 获取 Woocommerce 3 中的订单费用项目详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47669922/

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