Back to Woocommerce

Product variations

docs/apis/rest-api/v3/product-variations.mdx

10.9.0-dev45.5 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Product variations

The product variations API allows you to create, view, update, and delete individual, or a batch, of product variations.

Product variation properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
date_createddate-timeThe date the variation was created, in the site's timezone. READ-ONLY
date_created_gmtdate-timeThe date the variation was created, as GMT. READ-ONLY
date_modifieddate-timeThe date the variation was last modified, in the site's timezone. READ-ONLY
date_modified_gmtdate-timeThe date the variation was last modified, as GMT. READ-ONLY
descriptionstringVariation description.
permalinkstringVariation URL. READ-ONLY
skustringUnique identifier.
global_unique_idstringGTIN, UPC, EAN or ISBN. A global unique identifier for the variation.
pricestringCurrent variation price. READ-ONLY
regular_pricestringVariation regular price.
sale_pricestringVariation sale price.
date_on_sale_fromdate-timeStart date of sale price, in the site's timezone.
date_on_sale_from_gmtdate-timeStart date of sale price, as GMT.
date_on_sale_todate-timeEnd date of sale price, in the site's timezone.
date_on_sale_to_gmtdate-timeEnd date of sale price, as GMT.
on_salebooleanShows if the variation is on sale. READ-ONLY
statusstringVariation status. Options: draft, pending, private and publish. Default is publish.
purchasablebooleanShows if the variation can be bought. READ-ONLY
virtualbooleanIf the variation is virtual. Default is false.
downloadablebooleanIf the variation is downloadable. Default is false.
downloadsarrayList of downloadable files. See Product variation - Downloads properties
download_limitintegerNumber of times downloadable files can be downloaded after purchase. Default is -1.
download_expiryintegerNumber of days until access to downloadable files expires. Default is -1.
tax_statusstringTax status. Options: taxable, shipping and none. Default is taxable.
tax_classstringTax class.
manage_stockboolean, stringStock management at variation level. Possible values are either a boolean or parent. Default is false.
stock_quantityintegerStock quantity.
stock_statusstringControls the stock status of the product. Options: instock, outofstock, onbackorder. Default is instock.
backordersstringIf managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no.
backorders_allowedbooleanShows if backorders are allowed. READ-ONLY
backorderedbooleanShows if the variation is on backordered. READ-ONLY
weightstringVariation weight.
dimensionsobjectVariation dimensions. See Product variation - Dimensions properties
shipping_classstringShipping class slug.
shipping_class_idstringShipping class ID. READ-ONLY
imageobjectVariation image data. See Product variation - Image properties
gallery_image_idsarrayVariation gallery image IDs, excluding the featured image (which is set via image).
attributesarrayList of attributes. See Product variation - Attributes properties
menu_orderintegerMenu order, used to custom sort products.
meta_dataarrayMeta data. See Product variation - Meta data properties

Product variation - Downloads properties

AttributeTypeDescription
idstringFile ID.
namestringFile name.
filestringFile URL.

Product variation - Dimensions properties

AttributeTypeDescription
lengthstringVariation length.
widthstringVariation width.
heightstringVariation height.

Product variation - Image properties

AttributeTypeDescription
idintegerImage ID.
date_createddate-timeThe date the image was created, in the site's timezone. READ-ONLY
date_created_gmtdate-timeThe date the image was created, as GMT. READ-ONLY
date_modifieddate-timeThe date the image was last modified, in the site's timezone. READ-ONLY
date_modified_gmtdate-timeThe date the image was last modified, as GMT. READ-ONLY
srcstringImage URL.
namestringImage name.
altstringImage alternative text.

Product variation - Attributes properties

AttributeTypeDescription
idintegerAttribute ID.
namestringAttribute name.
optionstringSelected attribute term name.

Product variation - Meta data properties

AttributeTypeDescription
idintegerMeta ID. READ-ONLY
keystringMeta key.
valuestringMeta value.

Create a product variation

This API helps you to create a new product variation.

http
POST /wp-json/wc/v3/products/<product_id>/variations
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X POST https://example.com/wp-json/wc/v3/products/22/variations \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "regular_price": "9.00",
  "image": {
    "id": 423
  },
  "attributes": [
    {
      "id": 6,
      "option": "Black"
    }
  ]
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	regular_price: '9.00',
	image: {
		id: 423,
	},
	attributes: [
		{
			id: 9,
			option: 'Black',
		},
	],
};

WooCommerce.post( 'products/22/variations', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'regular_price' => '9.00',
    'image' => [
        'id' => 423
    ],
    'attributes' => [
        [
            'id' => 9,
            'option' => 'Black'
        ]
    ]
];

print_r($woocommerce->post('products/22/variations', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "regular_price": "9.00",
    "image": {
        "id": 423
    },
    "attributes": [
        {
            "id": 9,
            "option": "Black"
        }
    ]
}

print(wcapi.post("products/22/variations", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  regular_price: "9.00",
  image: {
    id: 423
  },
  attributes: [
    {
      id: 9,
      option: "Black"
    }
  ]
}

woocommerce.post("products/22/variations", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"id": 732,
	"date_created": "2017-03-23T00:36:38",
	"date_created_gmt": "2017-03-23T03:36:38",
	"date_modified": "2017-03-23T00:36:38",
	"date_modified_gmt": "2017-03-23T03:36:38",
	"description": "",
	"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black",
	"sku": "",
	"price": "9.00",
	"regular_price": "9.00",
	"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": true,
	"purchasable": true,
	"virtual": false,
	"downloadable": false,
	"downloads": [],
	"download_limit": -1,
	"download_expiry": -1,
	"tax_status": "taxable",
	"tax_class": "",
	"manage_stock": false,
	"stock_quantity": null,
	"stock_status": "instock",
	"backorders": "no",
	"backorders_allowed": false,
	"backordered": false,
	"weight": "",
	"dimensions": {
		"length": "",
		"width": "",
		"height": ""
	},
	"shipping_class": "",
	"shipping_class_id": 0,
	"image": {
		"id": 423,
		"date_created": "2016-10-19T12:21:14",
		"date_created_gmt": "2016-10-19T16:21:14",
		"date_modified": "2016-10-19T12:21:14",
		"date_modified_gmt": "2016-10-19T16:21:14",
		"src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg",
		"name": "",
		"alt": ""
	},
	"gallery_image_ids": [],
	"attributes": [
		{
			"id": 6,
			"name": "Color",
			"option": "Black"
		}
	],
	"menu_order": 0,
	"meta_data": [],
	"_links": {
		"self": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations/732"
			}
		],
		"collection": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations"
			}
		],
		"up": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22"
			}
		]
	}
}
</TabItem> </Tabs>

Retrieve a product variation

This API lets you retrieve and view a specific product variation by ID.

http
GET /wp-json/wc/v3/products/<product_id>/variations/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/products/22/variations/732 \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'products/22/variations/732' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('products/22/variations/732')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("products/22/variations/732").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("products/22/variations/732").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"id": 732,
	"date_created": "2017-03-23T00:36:38",
	"date_created_gmt": "2017-03-23T03:36:38",
	"date_modified": "2017-03-23T00:36:38",
	"date_modified_gmt": "2017-03-23T03:36:38",
	"description": "",
	"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black",
	"sku": "",
	"price": "9.00",
	"regular_price": "9.00",
	"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": false,
	"stock_quantity": null,
	"stock_status": "instock",
	"backorders": "no",
	"backorders_allowed": false,
	"backordered": false,
	"weight": "",
	"dimensions": {
		"length": "",
		"width": "",
		"height": ""
	},
	"shipping_class": "",
	"shipping_class_id": 0,
	"image": {
		"id": 423,
		"date_created": "2016-10-19T12:21:14",
		"date_created_gmt": "2016-10-19T16:21:14",
		"date_modified": "2016-10-19T12:21:14",
		"date_modified_gmt": "2016-10-19T16:21:14",
		"src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg",
		"name": "",
		"alt": ""
	},
	"gallery_image_ids": [],
	"attributes": [
		{
			"id": 6,
			"name": "Color",
			"option": "Black"
		}
	],
	"menu_order": 0,
	"meta_data": [],
	"_links": {
		"self": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations/732"
			}
		],
		"collection": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations"
			}
		],
		"up": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22"
			}
		]
	}
}
</TabItem> </Tabs>

List all product variations

This API helps you to view all the product variations.

http
GET /wp-json/wc/v3/products/<product_id>/variations
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/products/22/variations \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'products/22/variations' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('products/22/variations')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("products/22/variations").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("products/22/variations").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"id": 733,
		"date_created": "2017-03-23T00:53:11",
		"date_created_gmt": "2017-03-23T03:53:11",
		"date_modified": "2017-03-23T00:53:11",
		"date_modified_gmt": "2017-03-23T03:53:11",
		"description": "",
		"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green",
		"sku": "",
		"price": "9.00",
		"regular_price": "9.00",
		"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": false,
		"stock_quantity": null,
		"stock_status": "instock",
		"backorders": "no",
		"backorders_allowed": false,
		"backordered": false,
		"weight": "",
		"dimensions": {
			"length": "",
			"width": "",
			"height": ""
		},
		"shipping_class": "",
		"shipping_class_id": 0,
		"image": {
			"id": 425,
			"date_created": "2016-10-19T12:21:16",
			"date_created_gmt": "2016-10-19T16:21:16",
			"date_modified": "2016-10-19T12:21:16",
			"date_modified_gmt": "2016-10-19T16:21:16",
			"src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg",
			"name": "",
			"alt": ""
		},
		"gallery_image_ids": [],
		"attributes": [
			{
				"id": 6,
				"name": "Color",
				"option": "Green"
			}
		],
		"menu_order": 0,
		"meta_data": [],
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22/variations/733"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22/variations"
				}
			],
			"up": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22"
				}
			]
		}
	},
	{
		"id": 732,
		"date_created": "2017-03-23T00:36:38",
		"date_created_gmt": "2017-03-23T03:36:38",
		"date_modified": "2017-03-23T00:36:38",
		"date_modified_gmt": "2017-03-23T03:36:38",
		"description": "",
		"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black",
		"sku": "",
		"price": "9.00",
		"regular_price": "9.00",
		"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": false,
		"stock_quantity": null,
		"stock_status": "instock",
		"backorders": "no",
		"backorders_allowed": false,
		"backordered": false,
		"weight": "",
		"dimensions": {
			"length": "",
			"width": "",
			"height": ""
		},
		"shipping_class": "",
		"shipping_class_id": 0,
		"image": {
			"id": 423,
			"date_created": "2016-10-19T12:21:14",
			"date_created_gmt": "2016-10-19T16:21:14",
			"date_modified": "2016-10-19T12:21:14",
			"date_modified_gmt": "2016-10-19T16:21:14",
			"src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg",
			"name": "",
			"alt": ""
		},
		"gallery_image_ids": [],
		"attributes": [
			{
				"id": 6,
				"name": "Color",
				"option": "Black"
			}
		],
		"menu_order": 0,
		"meta_data": [],
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22/variations/732"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22/variations"
				}
			],
			"up": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/22"
				}
			]
		}
	}
]
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
pageintegerCurrent page of the collection. Default is 1.
per_pageintegerMaximum number of items to be returned in result set. Default is 10.
searchstringLimit results to those matching a string.
afterstringLimit response to resources published after a given ISO8601 compliant date.
beforestringLimit response to resources published before a given ISO8601 compliant date.
dates_are_gmtbooleanInterpret after and before as UTC dates when true.
excludearrayEnsure result set excludes specific IDs.
includearrayLimit result set to specific ids.
offsetintegerOffset the result set by a specific number of items.
orderstringOrder sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderbystringSort collection by object attribute. Options: date, modified, id, include, title and slug. Default is date.
parentarrayLimit result set to those of particular parent IDs.
parent_excludearrayLimit result set to all items except those of a particular parent ID.
slugstringLimit result set to products with a specific slug.
statusstringLimit result set to products assigned a specific status. Options: any, draft, pending, private and publish. Default is any.
include_statusstringLimit result set to product variations with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the status parameter. Options: any, future, trash, draft, pending, private, and publish.
exclude_statusstringExclude product variations from result set with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the include_status parameter. Options: future, trash, draft, pending, private, and publish.
skustringLimit result set to products with a specific SKU.
tax_classstringLimit result set to products with a specific tax class. Default options: standard, reduced-rate and zero-rate.
on_salebooleanLimit result set to products on sale.
min_pricestringLimit result set to products based on a minimum price.
max_pricestringLimit result set to products based on a maximum price.
stock_statusstringLimit result set to products with specified stock status. Options: instock, outofstock and onbackorder.
virtualbooleanLimit result set to virtual product variations
downloadablebooleanLimit result set to downloadable product variations.

Update a product variation

This API lets you make changes to a product variation.

http
PUT /wp-json/wc/v3/products/<product_id>/variations/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X PUT https://example.com/wp-json/wc/v3/products/22/variations/733 \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "regular_price": "10.00"
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	regular_price: '10.00',
};

WooCommerce.put( 'products/22/variations/733', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'regular_price' => '10.00'
];

print_r($woocommerce->put('products/22/variations/733', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "regular_price": "10.00"
}

print(wcapi.put("products/22/variations/733", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  regular_price: "10.00"
}

woocommerce.put("products/22/variations/733", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"id": 733,
	"date_created": "2017-03-23T00:53:11",
	"date_created_gmt": "2017-03-23T03:53:11",
	"date_modified": "2017-03-23T00:53:11",
	"date_modified_gmt": "2017-03-23T03:53:11",
	"description": "",
	"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green",
	"sku": "",
	"price": "10.00",
	"regular_price": "10.00",
	"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": false,
	"stock_quantity": null,
	"stock_status": "instock",
	"backorders": "no",
	"backorders_allowed": false,
	"backordered": false,
	"weight": "",
	"dimensions": {
		"length": "",
		"width": "",
		"height": ""
	},
	"shipping_class": "",
	"shipping_class_id": 0,
	"image": {
		"id": 425,
		"date_created": "2016-10-19T12:21:16",
		"date_created_gmt": "2016-10-19T16:21:16",
		"date_modified": "2016-10-19T12:21:16",
		"date_modified_gmt": "2016-10-19T16:21:16",
		"src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg",
		"name": "",
		"alt": ""
	},
	"gallery_image_ids": [],
	"attributes": [
		{
			"id": 6,
			"name": "Color",
			"option": "Green"
		}
	],
	"menu_order": 0,
	"meta_data": [],
	"_links": {
		"self": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations/733"
			}
		],
		"collection": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations"
			}
		],
		"up": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22"
			}
		]
	}
}
</TabItem> </Tabs>

Delete a product variation

This API helps you delete a product variation.

http
DELETE /wp-json/wc/v3/products/<product_id>/variations/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X DELETE https://example.com/wp-json/wc/v3/products/22/variations/733?force=true \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.delete( 'products/22/variations/733', {
	force: true,
} )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->delete('products/22/variations/733', ['force' => true])); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.delete("products/22/variations/733", params={"force": True}).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.delete("products/22/variations/733", force: true).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"id": 733,
	"date_created": "2017-03-23T00:53:11",
	"date_created_gmt": "2017-03-23T03:53:11",
	"date_modified": "2017-03-23T00:53:11",
	"date_modified_gmt": "2017-03-23T03:53:11",
	"description": "",
	"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green",
	"sku": "",
	"price": "10.00",
	"regular_price": "10.00",
	"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": false,
	"stock_quantity": null,
	"stock_status": "instock",
	"backorders": "no",
	"backorders_allowed": false,
	"backordered": false,
	"weight": "",
	"dimensions": {
		"length": "",
		"width": "",
		"height": ""
	},
	"shipping_class": "",
	"shipping_class_id": 0,
	"image": {
		"id": 425,
		"date_created": "2016-10-19T12:21:16",
		"date_created_gmt": "2016-10-19T16:21:16",
		"date_modified": "2016-10-19T12:21:16",
		"date_modified_gmt": "2016-10-19T16:21:16",
		"src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg",
		"name": "",
		"alt": ""
	},
	"gallery_image_ids": [],
	"attributes": [
		{
			"id": 6,
			"name": "Color",
			"option": "Green"
		}
	],
	"menu_order": 0,
	"meta_data": [],
	"_links": {
		"self": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations/733"
			}
		],
		"collection": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22/variations"
			}
		],
		"up": [
			{
				"href": "https://example.com/wp-json/wc/v3/products/22"
			}
		]
	}
}
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
forcestringRequired to be true, as resource does not support trashing.

Batch update product variations

This API helps you to batch create, update and delete multiple product variations.

:::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. :::

http
POST /wp-json/wc/v3/products/<product_id>/variations/batch
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X POST https://example.com/wp-json/wc/v3/products/22/variations/batch \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "create": [
    {
      "regular_price": "10.00",
      "attributes": [
        {
          "id": 6,
          "option": "Blue"
        }
      ]
    },
    {
      "regular_price": "10.00",
      "attributes": [
        {
          "id": 6,
          "option": "White"
        }
      ]
    }
  ],
  "update": [
    {
      "id": 733,
      "regular_price": "10.00"
    }
  ],
  "delete": [
    732
  ]
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	create: [
		{
			regular_price: '10.00',
			attributes: [
				{
					id: 6,
					option: 'Blue',
				},
			],
		},
		{
			regular_price: '10.00',
			attributes: [
				{
					id: 6,
					option: 'White',
				},
			],
		},
	],
	update: [
		{
			id: 733,
			regular_price: '10.00',
		},
	],
	delete: [ 732 ],
};

WooCommerce.post( 'products/22/variations/batch', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'create' => [
        [
            'regular_price' => '10.00',
            'attributes' => [
                [
                    'id' => 6,
                    'option' => 'Blue'
                ]
            ]
        ],
        [
            'regular_price' => '10.00',
            'attributes' => [
                [
                    'id' => 6,
                    'option' => 'White'
                ]
            ]
        ]
    ],
    'update' => [
        [
            'id' => 733,
            'regular_price' => '10.00'
        ]
    ],
    'delete' => [
        732
    ]
];

print_r($woocommerce->post('products/22/variations/batch', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "create": [
        {
            "regular_price": "10.00",
            "attributes": [
                {
                    "id": 6,
                    "option": "Blue"
                }
            ]
        },
        {
            "regular_price": "10.00",
            "attributes": [
                {
                    "id": 6,
                    "option": "White"
                }
            ]
        }
    ],
    "update": [
        {
            "id": 733,
            "regular_price": "10.00"
        }
    ],
    "delete": [
        732
    ]
}

print(wcapi.post("products/22/variations/batch", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  create: [
    {
      regular_price: "10.00",
      attributes: [
        {
          id: 6,
          option: "Blue"
        }
      ]
    },
    {
      regular_price: "10.00",
      attributes: [
        {
          id: 6,
          option: "White"
        }
      ]
    }
  ],
  update: [
    {
      id: 733,
      regular_price: "10.00"
    }
  ],
  delete: [
    732
  ]
}

woocommerce.post("products/22/variations/batch", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"create": [
		{
			"id": 735,
			"date_created": "2017-03-23T01:19:37",
			"date_created_gmt": "2017-03-23T04:19:37",
			"date_modified": "2017-03-23T01:19:37",
			"date_modified_gmt": "2017-03-23T04:19:37",
			"description": "",
			"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=blue",
			"sku": "",
			"price": "10.00",
			"regular_price": "10.00",
			"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": false,
			"stock_quantity": null,
			"stock_status": "instock",
			"backorders": "no",
			"backorders_allowed": false,
			"backordered": false,
			"weight": "",
			"dimensions": {
				"length": "",
				"width": "",
				"height": ""
			},
			"shipping_class": "",
			"shipping_class_id": 0,
			"image": {
				"id": 0,
				"date_created": "2017-03-22T22:19:40",
				"date_created_gmt": "2017-03-23T04:19:40",
				"date_modified": "2017-03-22T22:19:40",
				"date_modified_gmt": "2017-03-23T04:19:40",
				"src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png",
				"name": "Placeholder",
				"alt": "Placeholder"
			},
			"gallery_image_ids": [],
			"attributes": [
				{
					"id": 6,
					"name": "Color",
					"option": "Blue"
				}
			],
			"menu_order": 0,
			"meta_data": [],
			"_links": {
				"self": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations/735"
					}
				],
				"collection": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations"
					}
				],
				"up": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22"
					}
				]
			}
		},
		{
			"id": 736,
			"date_created": "2017-03-23T01:19:40",
			"date_created_gmt": "2017-03-23T04:19:40",
			"date_modified": "2017-03-23T01:19:40",
			"date_modified_gmt": "2017-03-23T04:19:40",
			"description": "",
			"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=white",
			"sku": "",
			"price": "10.00",
			"regular_price": "10.00",
			"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": false,
			"stock_quantity": null,
			"stock_status": "instock",
			"backorders": "no",
			"backorders_allowed": false,
			"backordered": false,
			"weight": "",
			"dimensions": {
				"length": "",
				"width": "",
				"height": ""
			},
			"shipping_class": "",
			"shipping_class_id": 0,
			"image": {
				"id": 0,
				"date_created": "2017-03-22T22:19:42",
				"date_created_gmt": "2017-03-23T04:19:42",
				"date_modified": "2017-03-22T22:19:42",
				"date_modified_gmt": "2017-03-23T04:19:42",
				"src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png",
				"name": "Placeholder",
				"alt": "Placeholder"
			},
			"gallery_image_ids": [],
			"attributes": [
				{
					"id": 6,
					"name": "Color",
					"option": "White"
				}
			],
			"menu_order": 0,
			"meta_data": [],
			"_links": {
				"self": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations/736"
					}
				],
				"collection": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations"
					}
				],
				"up": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22"
					}
				]
			}
		}
	],
	"update": [
		{
			"id": 733,
			"date_created": "2017-03-23T00:53:11",
			"date_created_gmt": "2017-03-23T03:53:11",
			"date_modified": "2017-03-23T00:53:11",
			"date_modified_gmt": "2017-03-23T03:53:11",
			"description": "",
			"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green",
			"sku": "",
			"price": "10.00",
			"regular_price": "10.00",
			"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": false,
			"stock_quantity": null,
			"stock_status": "instock",
			"backorders": "no",
			"backorders_allowed": false,
			"backordered": false,
			"weight": "",
			"dimensions": {
				"length": "",
				"width": "",
				"height": ""
			},
			"shipping_class": "",
			"shipping_class_id": 0,
			"image": {
				"id": 425,
				"date_created": "2016-10-19T12:21:16",
				"date_created_gmt": "2016-10-19T16:21:16",
				"date_modified": "2016-10-19T12:21:16",
				"date_modified_gmt": "2016-10-19T16:21:16",
				"src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg",
				"name": "",
				"alt": ""
			},
			"gallery_image_ids": [],
			"attributes": [
				{
					"id": 6,
					"name": "Color",
					"option": "Green"
				}
			],
			"menu_order": 0,
			"meta_data": [],
			"_links": {
				"self": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations/733"
					}
				],
				"collection": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations"
					}
				],
				"up": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22"
					}
				]
			}
		}
	],
	"delete": [
		{
			"id": 732,
			"date_created": "2017-03-23T00:36:38",
			"date_created_gmt": "2017-03-23T03:36:38",
			"date_modified": "2017-03-23T00:36:38",
			"date_modified_gmt": "2017-03-23T03:36:38",
			"description": "",
			"permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black",
			"sku": "",
			"price": "9.00",
			"regular_price": "9.00",
			"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": false,
			"stock_quantity": null,
			"stock_status": "instock",
			"backorders": "no",
			"backorders_allowed": false,
			"backordered": false,
			"weight": "",
			"dimensions": {
				"length": "",
				"width": "",
				"height": ""
			},
			"shipping_class": "",
			"shipping_class_id": 0,
			"image": {
				"id": 423,
				"date_created": "2016-10-19T12:21:14",
				"date_created_gmt": "2016-10-19T16:21:14",
				"date_modified": "2016-10-19T12:21:14",
				"date_modified_gmt": "2016-10-19T16:21:14",
				"src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg",
				"name": "",
				"alt": ""
			},
			"gallery_image_ids": [],
			"attributes": [
				{
					"id": 6,
					"name": "Color",
					"option": "Black"
				}
			],
			"menu_order": 0,
			"meta_data": [],
			"_links": {
				"self": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations/732"
					}
				],
				"collection": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22/variations"
					}
				],
				"up": [
					{
						"href": "https://example.com/wp-json/wc/v3/products/22"
					}
				]
			}
		}
	]
}
</TabItem> </Tabs>