WooCommerce REST API 产品不创建属性

时间:2021-03-22 23:04:31

标签: woocommerce woocommerce-rest-api

我看过一个类似的帖子,但我还没有找到答案。你能帮我吗?

我正在尝试使用 woocommerce REST API 创建可变产品,但似乎没有创建变体的属性。这些是我的步骤:

  1. 为变量类型的产品发送一个post请求,指定2个属性(颜色和尺寸)。这似乎是问题所在,因为响应没有显示任何属性,如果我去编辑产品,属性(颜色和尺寸)似乎不存在。我已经尝试了全局和产品级别的属性。

  2. 使用第 1 步中的变体组合发送创建产品变体的帖子请求。我没有收到任何错误,但似乎没有创建产品,变体也没有出现在我的商店网站上或当我在网站管理员中编辑产品。

我会在这里发布我的电话和回复,我真的希望你能帮助我。我试过使用 V2 和 V3 API,但没有区别。

非常感谢!!!!

1A:我对可变产品的 POST:

    "name": "CHAPEU HERING FEM",
    "slug": "CHAPEU HERING FEM",
    "type": "variable",
    "description": "CHAPEU HERING FEM",
    "short_description": "CHAPEU HERING FEM",
    "tags": [
        {
            "name": "KVTA"
        }
    ],
    "sku": "KVTA",
    "manage_stock": true,
    "categories": [
        {
            "id": 46
        },
        {
            "id": 47
        },
        {
            "id": 48
        }
    ],
    "attributes": [
        {
            "name": "Size",
            "position": 0,
            "visible": true,
            "variation": true,
            "Options": [
                "G",
                "M"
            ]
        },
        {
            "name": "Color",
            "position": 0,
            "visible": true,
            "variation": true,
            "Options": [
                "BEGE"
            ]
        }
    ]
}

1B:我得到的回应。请注意,响应不会给我任何错误,但也不会返回属性。

    "id": 1500,
    "name": "CHAPEU HERING FEM",
    "slug": "chapeu-hering-fem",
    "permalink": "https://woocriar.com/product/chapeu-hering-fem/",
    "date_created": "2021-03-22T12:32:46",
    "date_created_gmt": "2021-03-22T12:32:46",
    "date_modified": "2021-03-22T12:32:46",
    "date_modified_gmt": "2021-03-22T12:32:46",
    "type": "variable",
    "status": "publish",
    "featured": false,
    "catalog_visibility": "visible",
    "description": "CHAPEU HERING FEM",
    "short_description": "CHAPEU HERING FEM",
    "sku": "KVTA",
    "price": "",
    "regular_price": "",
    "sale_price": "",
    "date_on_sale_from": null,
    "date_on_sale_from_gmt": null,
    "date_on_sale_to": null,
    "date_on_sale_to_gmt": null,
    "on_sale": false,
    "purchasable": false,
    "total_sales": 0,
    "virtual": false,
    "downloadable": false,
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "external_url": "",
    "button_text": "",
    "tax_status": "taxable",
    "tax_class": "",
    "manage_stock": true,
    "stock_quantity": null,
    "backorders": "no",
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": false,
    "weight": "",
    "dimensions": {
        "length": "",
        "width": "",
        "height": ""
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": 0,
    "reviews_allowed": true,
    "average_rating": "0",
    "rating_count": 0,
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "purchase_note": "",
    "categories": [
        {
            "id": 46,
            "name": "ACESSÓRIO",
            "slug": "acessorio"
        },
        {
            "id": 47,
            "name": "CHAPÉU",
            "slug": "chapeu"
        },
        {
            "id": 48,
            "name": "Feminino",
            "slug": "feminino"
        }
    ],
    "tags": [],
    "images": [],
    "attributes": [],
    "default_attributes": [],
    "variations": [],
    "grouped_products": [],
    "menu_order": 0,
    "price_html": "",
    "related_ids": [],
    "meta_data": [],
    "stock_status": "outofstock",
    "_links": {
        "self": [
            {
                "href": "https://woocriar.com/wp-json/wc/v3/products/1500"
            }
        ],
        "collection": [
            {
                "href": "https://woocriar.com/wp-json/wc/v3/products"
            }
        ]
    }
}

2A:我发布的产品变体

    "sku": "0001047123",
    "regular_price": "65.90",
    "manage_stock": true,
    "status": "publish",
    "stock_quantity": 1,
    "attributes": [
        {
            "name": "Size",
            "option": "G"
        },
        {
            "name": "Color",
            "option": "BEGE"
        }
    ]
}

2B。我得到的回应。看起来不错,但它不会显示在我的商店中,也不会在我尝试编辑产品时显示。

    "id": 1501,
    "date_created": "2021-03-22T12:34:37",
    "date_created_gmt": "2021-03-22T12:34:37",
    "date_modified": "2021-03-22T12:34:37",
    "date_modified_gmt": "2021-03-22T12:34:37",
    "description": "",
    "permalink": "https://woocriar.com/product/chapeu-hering-fem/",
    "sku": "0001047123",
    "price": "65.90",
    "regular_price": "65.90",
    "sale_price": "",
    "date_on_sale_from": null,
    "date_on_sale_from_gmt": null,
    "date_on_sale_to": null,
    "date_on_sale_to_gmt": null,
    "on_sale": false,
    "status": "publish",
    "purchasable": true,
    "virtual": false,
    "downloadable": false,
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "tax_status": "taxable",
    "tax_class": "",
    "manage_stock": true,
    "stock_quantity": 1,
    "stock_status": "instock",
    "backorders": "no",
    "backorders_allowed": false,
    "backordered": false,
    "weight": "",
    "dimensions": {
        "length": "",
        "width": "",
        "height": ""
    },
    "shipping_class": "",
    "shipping_class_id": 0,
    "image": null,
    "attributes": [],
    "menu_order": 0,
    "meta_data": [],
    "_links": {
        "self": [
            {
                "href": "https://woocriar.com/wp-json/wc/v3/products/1500/variations/1501"
            }
        ],
        "collection": [
            {
                "href": "https://woocriar.com/wp-json/wc/v3/products/1500/variations"
            }
        ],
        "up": [
            {
                "href": "https://woocriar.com/wp-json/wc/v3/products/1500"
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:0)

只是为了澄清我有一个解决方案。我的 POST 有“选项”而不是“选项”(大写“O”),仅此而已。它没有返回任何错误,只是没有做任何事情。 在属性选项上使用小写“o”后,它起作用了。

谢谢大家。