I'm trying to manage WooCommerce entirely by its REST API but with no luck, i'm trying to insert a product with variations
{{url}}/wp-json/wc/v3/products/
{{url}}/wp-json/wc/v3/products/{{product_id}}/variations
, this works too{{url}}/wp-json/wc/v3/products/{{product_id}}/variations
and its own GET {{url}}/wp-json/wc/v3/products/{{product_id}}/variations/{{variation_id}}
However, i'm not able to see any product variations on the woocommerce product page
What i found its that a product with variations that work have an array variations
which contains the variations ids, but when i create a product with API the array of the product created is empty, this would explain why i'm not able to see any product variation on the product page.
This is a sample of product variation that I create:
{
"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"
}
]}
I was not able to found a similar issue, any thoughts?
The problem could be in the product creation process. I can't know for sure without looking at the data used for product creation, but I'll try anyway. I see that you use two different attributes for the variants. So, the products should be created to support those attributes correctly:
{
"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' ]
}
}
}
If "variation": true
is missing in the main product's attributes, then the variants created under attributes without that flag won't show up as variants. I know it's a shot in the dark, but maybe it'll help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With