draxq02664 2017-12-06 08:32
浏览 173
已采纳

在Woocommerce 3中获取订单费用项目详细信息

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.

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

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

                        )

                )
  • 写回答

1条回答 默认 最新

  • duanfu6160 2017-12-06 15:14
    关注

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

    Tested and works

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度