获取 Woocommerce 3 中的订单费用项目详细信息 [英] Get the order fee item details in Woocommerce 3

查看:47
本文介绍了获取 Woocommerce 3 中的订单费用项目详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我尝试使用函数 get_name () 但它不起作用.

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

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

                        )

                )

推荐答案

要访问和使用 Order Fee 项目的属性,您需要使用 WC_Order_Item_Fee 方法首先使用 foreach 循环这种方式:

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:

// (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();
}

经过测试并有效

这篇关于获取 Woocommerce 3 中的订单费用项目详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆