Woocommerce rest api:更改响应输出以将货运单据和费用单据转换为订单项

时间:2018-10-31 15:43:05

标签: wordpress rest api woocommerce

我需要更改woocommerce rest api响应代码的输出,以将费用{fee_lines}和运费{shipping_lines}转换为订单项{line_items}。

示例:这是原始输出,信息较少,易于阅读:

{
    "id": 15862,
    "number": "15862",
    "line_items": [
        {
            "id": 213,
            "name": "My product",
            "product_id": 13214,
            "quantity": 1,
            "sku": "1111",
            "price": 20
        },
        {
            "id": 214,
            "name": "My product 2",
            "product_id": 1234,
            "quantity": 2,
            "sku": "1211",
            "price": 14
        }
    ],

    "shipping_lines": [
        {
            "id": 217,
            "method_title": "Colissimo",
            "total": "7.50",
            "total_tax": "1.50"
        }
    ],
    "fee_lines": [
        {
            "id": 215,
            "name": "addon",
            "amount": "50",
            "total": "50.00",
            "total_tax": "10.00"
        },
        {
            "id": 216,
            "name": "2-Dream 14cl cristal - Coupe de champagne personnalisée: Conception Conception avec un dessin",
            "tax_class": "",
            "tax_status": "taxable",
            "amount": "12.5",
            "total": "12.50",
            "total_tax": "2.50"
        }
      ]
}

我的发票系统所需的输出仅识别订单项,因此我需要使货运行和费用行看起来像订单项。

以下是我需要的示例:

{
    "id": 15862,
    "number": "15862",
    "line_items": [
        {
            "id": 213,
            "name": "My product",
            "product_id": 13214,
            "quantity": 1,
            "sku": "1111",
            "price": 20
        },
        {
            "id": 214,
            "name": "My product 2",
            "product_id": 1234,
            "quantity": 2,
            "sku": "1211",
            "price": 14
        },
        {
            "id": 215,
            "name": "fee", * this value needs to be retrieved from the order
            "product_id": 1234, *can use a generic product id
            "quantity": 1, *can be set to 1 always
            "sku": "1211"
            "price": 7.5 *this value needs to be retrieved from the order fees
        }, 
        {
            "id": 216,
            "name": "fee 2", *this value needs to be retrieved from the order fees
            "product_id": 1234,* can use a generic product id
            "quantity": 1, *can be set to 1 always
            "sku": "1211", *can be set manually
            "price": 7.5 *this value needs to be retrieved from the order fees
        },
        {
            "id": 217, *this value needs to be retrieved from the order shipping
            "name": "Colissimo", *this value needs to be retrieved from the order shipping "method_title"
            "total": "7.50", *this value needs to be retrieved from the order shipping total
            "total_tax": "1.50" *this value needs to be retrieved from the order fees
        }
    ]
}

有人对如何解决这个问题有任何想法吗?谢谢

0 个答案:

没有答案