2017-12-06 10 views
1

私の注文に付いた手数料の名前を取得しようとしました。私はwoocommerceで配列を取得しましたが、名前を取得する方法はわかりません。Woocommerce 3の注文手数料明細を入手

私は機能get_name()で試しましたが、うまくいきません。

誰かが私を助けてくれますか?アクセスするには、あなたが最初にこの方法をforeachループを使用してWC_Order_Item_Fee方法を使用する必要が発注手数料項目のプロパティを使用する

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

         ) 

       ) 

答えて

2

$the_order->get_items(array('line_item', 'fee', 'shipping')); 

生データ出力を

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

テスト済み作品

関連する問題