首页 > 解决方案 > WooCommerce 看不到产品变化

问题描述

我正在尝试完全通过其REST API管理 WooCommerce,但没有运气,我正在尝试插入具有变体的产品

但是,我无法在 woocommerce 产品页面上看到任何产品变体

我发现具有变体的产品具有一个variations包含变体 ID 的数组,但是当我使用 API 创建产品时,创建的产品数组为空,这可以解释为什么我看不到任何产品产品页面上的变化。

这是我创建的产品变体示例:

{
"regular_price": "225",
"status": "publish",
"manage_stock": true,
"stock_quantity": 1,
"stock_status": "instock",
"image": {
  "src": "https://via.placeholder.com/150"
},
"on_sale": true,
"shipping_class": "1",
"attributes": [
  {
    "id": 2,
    "name": "Color",
    "option": "Red"
  },
  {
    "id": 3,
    "name": "Size",
    "option": "Xl"
  }
]}

我找不到类似的问题,有什么想法吗?

标签: wordpressrestwoocommercewoocommerce-rest-api

解决方案


问题可能出在产品创建过程中。如果不查看用于产品创建的数据,我无法确定,但无论如何我都会尝试。我看到您对变体使用了两种不同的属性。因此,应该创建产品以正确支持这些属性:

{
    "name": "Sample Product",
    "type": "Example",
    "description": "A Demo Product",
    "images": {
        {
            "src": "path/to/img",
            "position": 1
        }
    },
    "categories": {
        {
            "id": 12
        }
    },
    "attributes": {
        {
            "id": 2,
            "name": "Color",
            "variation": true,
            "visible": true,
            "options": [ 'Red', 'Green', 'Blue' ]
        },
        {
            "id": 3,
            "name": "Size",
            "variation": true,
            "visible": true,
            "options": [ 'M', 'L', 'XL' ]
        }
    }
}

如果"variation": true主要产品的属性中缺少,则在没有该标志的属性下创建的变体将不会显示为变体。我知道这是在黑暗中拍摄,但也许它会帮助你。


推荐阅读