curl --request GET \
--url {protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}import requests
url = "{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/products/{id}/variations/{variation_id}")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"id": 289,
"parent_id": 278,
"name": "Premium Cotton T-Shirt - Large, Navy Blue",
"slug": "premium-cotton-t-shirt-large-navy-blue",
"permalink": "https://example-store.com/product/premium-cotton-t-shirt/?attribute_pa_size=large&attribute_pa_color=navy-blue",
"sku": "PCT-2024-L-NAVY",
"description": "Premium Cotton T-Shirt in Large, Navy Blue",
"dates": {
"created": "2024-02-10T09:15:00",
"created_gmt": "2024-02-10T14:15:00",
"modified": "2024-09-18T11:45:00",
"modified_gmt": "2024-09-18T16:45:00"
},
"featured": false,
"prices": {
"price": "80.00",
"regular_price": "80.00",
"sale_price": "",
"price_range": null,
"on_sale": false,
"date_on_sale": {
"from": null,
"from_gmt": null,
"to": null,
"to_gmt": null
},
"currency": {
"code": "USD",
"symbol": "$",
"position": "left",
"decimal_separator": ".",
"thousand_separator": ",",
"decimals": 2
}
},
"hidden_conditions": {
"virtual": false,
"downloadable": false,
"manage_stock": true,
"sold_individually": false,
"shipping_required": true
},
"images": [
{
"id": 724,
"src": {
"thumbnail": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-150x150.jpg",
"medium": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-300x300.jpg",
"large": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-600x600.jpg",
"full": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy.jpg"
},
"name": "tshirt-navy",
"alt": "Premium Cotton T-Shirt in Navy Blue",
"position": 0,
"featured": true
}
],
"categories": [
{
"id": 15,
"name": "Clothing",
"slug": "clothing",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/categories/15"
},
{
"id": 22,
"name": "T-Shirts",
"slug": "t-shirts",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/categories/22"
}
],
"tags": [
{
"id": 8,
"name": "Premium",
"slug": "premium",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/tags/8"
}
],
"attributes": [
{
"id": 1,
"name": "Size",
"position": 0,
"visible": true,
"variation": true,
"options": [
"Large"
]
},
{
"id": 2,
"name": "Color",
"position": 1,
"visible": true,
"variation": true,
"options": [
"Navy Blue"
]
}
],
"stock": {
"is_in_stock": true,
"stock_quantity": 45,
"stock_status": "instock",
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"low_stock_amount": null
},
"weight": {
"value": "0.2",
"unit": "kg"
},
"dimensions": {
"length": "12",
"width": "10",
"height": "1",
"unit": "cm"
},
"total_sales": 156,
"add_to_cart": {
"text": "Add to cart",
"description": "Add Premium Cotton T-Shirt - Large, Navy Blue to your cart",
"is_purchasable": true,
"purchase_quantity": {
"min_purchase": 1,
"max_purchase": 45
},
"rest_url": "https://example-store.com/wp-json/cocart/v2/cart/add-item"
},
"meta_data": [
{
"key": "_fabric",
"value": "100% Cotton"
}
]
}{
"code": "cocart_invalid_id",
"message": "Invalid product or variation ID provided.",
"data": {
"status": 400
}
}{
"code": "cocart_variation_not_found",
"message": "Product variation not found.",
"data": {
"status": 404
}
}Gets a single variation for a variable product.
A valid request URL is required to generate request examples{
"id": 289,
"parent_id": 278,
"name": "Premium Cotton T-Shirt - Large, Navy Blue",
"slug": "premium-cotton-t-shirt-large-navy-blue",
"permalink": "https://example-store.com/product/premium-cotton-t-shirt/?attribute_pa_size=large&attribute_pa_color=navy-blue",
"sku": "PCT-2024-L-NAVY",
"description": "Premium Cotton T-Shirt in Large, Navy Blue",
"dates": {
"created": "2024-02-10T09:15:00",
"created_gmt": "2024-02-10T14:15:00",
"modified": "2024-09-18T11:45:00",
"modified_gmt": "2024-09-18T16:45:00"
},
"featured": false,
"prices": {
"price": "80.00",
"regular_price": "80.00",
"sale_price": "",
"price_range": null,
"on_sale": false,
"date_on_sale": {
"from": null,
"from_gmt": null,
"to": null,
"to_gmt": null
},
"currency": {
"code": "USD",
"symbol": "$",
"position": "left",
"decimal_separator": ".",
"thousand_separator": ",",
"decimals": 2
}
},
"hidden_conditions": {
"virtual": false,
"downloadable": false,
"manage_stock": true,
"sold_individually": false,
"shipping_required": true
},
"images": [
{
"id": 724,
"src": {
"thumbnail": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-150x150.jpg",
"medium": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-300x300.jpg",
"large": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy-600x600.jpg",
"full": "https://example-store.com/wp-content/uploads/2024/02/tshirt-navy.jpg"
},
"name": "tshirt-navy",
"alt": "Premium Cotton T-Shirt in Navy Blue",
"position": 0,
"featured": true
}
],
"categories": [
{
"id": 15,
"name": "Clothing",
"slug": "clothing",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/categories/15"
},
{
"id": 22,
"name": "T-Shirts",
"slug": "t-shirts",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/categories/22"
}
],
"tags": [
{
"id": 8,
"name": "Premium",
"slug": "premium",
"rest_url": "https://example-store.com/wp-json/cocart/v2/products/tags/8"
}
],
"attributes": [
{
"id": 1,
"name": "Size",
"position": 0,
"visible": true,
"variation": true,
"options": [
"Large"
]
},
{
"id": 2,
"name": "Color",
"position": 1,
"visible": true,
"variation": true,
"options": [
"Navy Blue"
]
}
],
"stock": {
"is_in_stock": true,
"stock_quantity": 45,
"stock_status": "instock",
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"low_stock_amount": null
},
"weight": {
"value": "0.2",
"unit": "kg"
},
"dimensions": {
"length": "12",
"width": "10",
"height": "1",
"unit": "cm"
},
"total_sales": 156,
"add_to_cart": {
"text": "Add to cart",
"description": "Add Premium Cotton T-Shirt - Large, Navy Blue to your cart",
"is_purchasable": true,
"purchase_quantity": {
"min_purchase": 1,
"max_purchase": 45
},
"rest_url": "https://example-store.com/wp-json/cocart/v2/cart/add-item"
},
"meta_data": [
{
"key": "_fabric",
"value": "100% Cotton"
}
]
}{
"code": "cocart_invalid_id",
"message": "Invalid product or variation ID provided.",
"data": {
"status": 400
}
}{
"code": "cocart_variation_not_found",
"message": "Product variation not found.",
"data": {
"status": 404
}
}Path Parameters
Unique identifier for the variable product.
Unique identifier for the variation.
Response
Product variation retrieved successfully.
CoCart v2 Product Variation object. Variations use the same structure as Product objects, but with the following fields removed: type, short_description, hidden_conditions.reviews_allowed, average_rating, review_count, rating_count, rated_out_of, reviews, default_attributes, variations, grouped_products, related, upsells, cross_sells, external_url, button_text, and add_to_cart.has_options.
Unique identifier for the variation
Product parent ID (the variable product this variation belongs to)
Variation name
Variation slug
Variation URL
Unique identifier (SKU)
Variation description
Variation dates
Show child attributes
Show child attributes
Whether the variation is featured
Variation pricing information
Show child attributes
Show child attributes
Variation conditional flags (note reviews_allowed is not present)
Show child attributes
Show child attributes
Variation images
Show child attributes
Show child attributes
Product categories (inherited from parent)
Show child attributes
Show child attributes
Product tags (inherited from parent)
Show child attributes
Show child attributes
Variation attributes
Show child attributes
Show child attributes
Stock information
Show child attributes
Show child attributes
Variation weight
Show child attributes
Show child attributes
Variation dimensions
Show child attributes
Show child attributes
Total number of sales for this variation
Add to cart information (note has_options is not present)
Show child attributes
Show child attributes
Meta data
Show child attributes
Show child attributes