获取 Woocommerce 3 中的订单费用项目详细信息
P粉438918323
P粉438918323 2024-02-21 10:23:55
0
1
344

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

                        )

                )

P粉438918323
P粉438918323

全部回复(1)
P粉436052364

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

经过测试并有效

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!