Reputation: 858
When adding variations to an existing products using the API, the shipping class and selected variation appears to be ignored. I am using NodeJS, with woocommerce-api v1.4.2
Using NodeJS and the above package attempt to add a variation to an existing product using the following payload:
{ sku: '12751_1551793442001',
regular_price: '198',
attributes:
[ { id: 1551793442001,
name: 'mount',
shipping_class: 'band-l',
option: 'Framed' } ] }
{ sku: '12751_1551793442002',
regular_price: '119',
attributes:
[ { id: 1551793442002,
name: 'mount',
shipping_class: 'band-i',
option: 'mounted' } ] }
{ sku: '12751_1551793442003',
regular_price: '109',
attributes:
[ { id: 1551793442003,
name: 'mount',
shipping_class: 'band-d',
option: 'Print only' } ] }
The variations are added, each with the correct price, but without the 'name' associated.
The shipping band is not set, even though being set in the API request, however the price IS set.
The postage band does already exist in WooCommerce
I'm at a bit of loss as to explain this, does anybody have any insight?
Upvotes: 1
Views: 518
Reputation: 858
After communicating with the WooCommerce devs, it seems there are two different types of attributes, local and global. Global attributes have an ID whereas local do not. To resolve my issue I omitted the ID and included the name:
Also, the shipping_class was in the wrong place.
{
sku: '12751_1551793442001',
regular_price: '198',
shipping_class: 'band-l',
attributes: [
{
name: 'mount',
option: 'Framed'
}
]
}
Upvotes: 1