【问题标题】:Get the order fee item details in Woocommerce 3在 Woocommerce 3 中获取订单费用项目详细信息
【发布时间】:2018-05-20 01:50:10
【问题描述】:

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

                        )

                )

【问题讨论】:

    标签: php wordpress woocommerce orders fee


    【解决方案1】:

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

    经过测试并且可以工作

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 2017-01-17
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多