php - PHP array add an extra same-array
问题描述
I create an API for a external invoice system. Everything works, but i can not add the shipping costs as an new line_item in the invoice.
Following some questions, the code has now been added more extensively.
By adding an exact same array ($ line_items), I hoped it worked. However, the system will then stop running.
function create_invoice($email,$order,$customer_id){
$api = new JorttBV_Client(APPID, APPTOKEN);
$items = $order->get_items();
//Shipping data
$shippingcount = $order_data['shipping_total'];
$shippingname = 'Verzending';
//Start arrays
$line_items = array();
//Add shipping costs
$line_items[] = array(
'vat' => 21,
'amount' => $shippingcount,
'quantity' => 1,
'description' => $shippingname
);
//Loop product data in array
foreach ( $items as $item_id => $item_data ) {
$tax = $item_data->get_total();
$tax2 = $item_data->get_total_tax();
$tax3 = ($tax2/$tax)*100;
$line_items[] = array(
'vat' => 21,
'amount' => number_format((float)$order->get_item_meta($item_id, '_line_subtotal', true),2,'.',''),
'quantity' => $order->get_item_meta($item_id, '_qty', true),
'description' => $item_data['name']
);
}
//Add data to invoice
$invoice = [
'invoice' => [
'customer_id' => $customer_id,
'delivery_period' => '',
"reference" => '',
"remarks" => '',
'line_items' => $line_items
]
];
$result = $api->request($invoice, 'invoices');
$res = json_decode($result);
/* echo "<pre>"; print_r($invoice);
echo "<pre>"; print_r($res);
die("1233"); */
$invoice_id =$res->invoice_id;
send_invoice($email,$invoice_id);
}
Any idea?
解决方案
推荐阅读
- javascript - 如何将输入字段值存储在 jquery td 标记内的变量中?
- java - Spring Boot 应用程序中对 REST 端点的自定义访问控制
- flutter - 如何让黄色容器扩展并填充其紫色父母可用的其余空间
- c++ - 复制构造函数和重载的加法运算符
- angular - 如何在 Angular Material 中更改 mat-form-field 边框颜色
- java - 在 Java 中使用通用链表结构创建 LinkedStack 时遇到问题
- python - 在 numpy 数组上应用“同时”多个条件
- gtk - jhbuild build 得到了我的系统上未安装的错误介子版本
- laravel - Laravel:一个模型中的多个表
- mysql - 错误:在 xampp 中启动 mysql 服务后 MySQL 意外关闭