WooCommerce REST API检索订购产品中的所有属性

问题描述 投票:0回答:1

我花了2天,无法解决,请帮助:/

我需要通过WooCommerce中的REST API(V3)来获取all产品属性。

我的示例订单包含2个产品,第一个是变量产品第二个是简单产品

现在使用时:

GET https://example.com/wp-json/wc/v3/orders/(order id)

我在订购的产品中检索> "line_items"将此数组排列:

[请查看“元数据”]

  "line_items": [
{
  "id": 80,
  "name": "THIS IS PRODUCT WITH VARIATIONS",
  "product_id": 4081734,
  "variation_id": 4081741,
  "quantity": 1,
  "tax_class": "",
  "subtotal": "267.48",
  "subtotal_tax": "61.52",
  "total": "267.48",
  "total_tax": "61.52",
  "taxes": [
    {
      "id": 1,
      "total": "61.5204",
      "subtotal": "61.5204"
    }
  ],
  "meta_data": [
    {
      "id": 669,
      "key": "pa_color",
      "value": "morski"
    },
    {
      "id": 670,
      "key": "pa_size",
      "value": "s"
    },
    {
      "id": 693,
      "key": "_reduced_stock",
      "value": "1"
    }
  ],
  "sku": "",
  "price": 267.48
},
{
  "id": 81,
  "name": "THIS IS SIMPLE PRODUCT",
  "product_id": 4081728,
  "variation_id": 0,
  "quantity": 1,
  "tax_class": "",
  "subtotal": "178.05",
  "subtotal_tax": "40.95",
  "total": "178.05",
  "total_tax": "40.95",
  "taxes": [
    {
      "id": 1,
      "total": "40.9515",
      "subtotal": "40.9515"
    }
  ],
  "meta_data": [
    {
      "id": 694,
      "key": "_reduced_stock",
      "value": "1"
    }
  ],
  "sku": "",
  "price": 178.05
}
],

“ meta_data”仅包含颜色和尺寸属性,并且仅在已选择它们的情况下包含。数据不足,我需要一些其他属性。

我所有的产品都有“ supplier”属性,例如“ supplierABC”:

  "attributes": [
{
  "id": 6,
  "name": "colour",
  "position": 0,
  "visible": true,
  "variation": true,
  "options": [
    "karmelowy",
    "morski"
  ]
},
{
  "id": 5,
  "name": "size",
  "position": 1,
  "visible": true,
  "variation": true,
  "options": [
    "S"
  ]
},
{
  "id": 11,
  "name": "supplier",
  "position": 4,
  "visible": false,
  "variation": false,
  "options": [
    "supplierABC"
  ]
}

],

我需要为GET Order中的每个订购商品都具有供应商属性。

简单产品和变体产品都需要它。

如何实现这些家伙?

我甚至尝试在产品自定义字段中添加此“供应商”,但REST API不会这样做。

wordpress woocommerce e-commerce custom-fields woocommerce-rest-api
1个回答
0
投票

您需要从该响应中提取产品ID,然后再次调用以从产品端点http://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product中检索产品属性。>

© www.soinside.com 2019 - 2024. All rights reserved.