wordpress - WooCommerce 看不到产品变化
问题描述
我正在尝试完全通过其REST API管理 WooCommerce,但没有运气,我正在尝试插入具有变体的产品
- 我可以通过 POST 成功创建产品
{{url}}/wp-json/wc/v3/products/
- 产品创建后,我必须使用 POST 创建其变体到一个单独的端点
{{url}}/wp-json/wc/v3/products/{{product_id}}/variations
,这也有效 - 我可以看到使用 GET in
{{url}}/wp-json/wc/v3/products/{{product_id}}/variations
和它自己的 GET创建的产品变体{{url}}/wp-json/wc/v3/products/{{product_id}}/variations/{{variation_id}}
- 我可以正确看到在 wordpress 数据库中创建的行
- 所有调用都是 201,期望对象作为响应
但是,我无法在 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"
}
]}
我找不到类似的问题,有什么想法吗?
解决方案
问题可能出在产品创建过程中。如果不查看用于产品创建的数据,我无法确定,但无论如何我都会尝试。我看到您对变体使用了两种不同的属性。因此,应该创建产品以正确支持这些属性:
{
"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
主要产品的属性中缺少,则在没有该标志的属性下创建的变体将不会显示为变体。我知道这是在黑暗中拍摄,但也许它会帮助你。
推荐阅读
- facebook - 使用 facebook 跟踪像素进行注册成功,但不会重定向到成功页面
- asp.net-mvc - 如何从 mvc 控制器返回 json 数据并查看
- excel - 与内置函数相比,UDF 运行缓慢
- icons - 这相当于显示国家图标的 FontAwesome 是什么?
- django - Openshift online - 不再运行 collectstatic
- assembly - STM32f103c8 gpio限速
- javascript - 制作一个独特的谷歌扩展密钥会弄乱扩展
- php - PHP - 为什么我的函数没有返回任何东西
- django - 通过ajax将每个键的多个值传递给模板
- java - 有没有办法在没有递归/堆栈的情况下对河内塔进行编程?