I want to construct the variation selector manually:
For example, some product has these variations:
color: red, green, blue
size: small, medium, large
When I run this code:
$product->get_available_variations();
I get 3 arrays returned:
[
{
"attributes": {
"attribute_pa_color": "red",
"attribute_pa_size": ""
},
"availability_html": "",
"backorders_allowed": false,
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"dimensions_html": "N/A",
"display_price": 20,
"display_regular_price": 20,
"image": {
"title": "vneck-tee-2.jpg",
"caption": "",
"url": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2.jpg",
"alt": "",
"src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-600x599.jpg",
"srcset": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-600x599.jpg 600w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-450x449.jpg 450w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-100x100.jpg 100w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-300x300.jpg 300w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-80x80.jpg 80w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-768x767.jpg 768w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2.jpg 801w",
"sizes": "(max-width: 600px) 100vw, 600px",
"full_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2.jpg",
"full_src_w": 801,
"full_src_h": 800,
"gallery_thumbnail_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-100x100.jpg",
"gallery_thumbnail_src_w": 100,
"gallery_thumbnail_src_h": 100,
"thumb_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vneck-tee-2-450x449.jpg",
"thumb_src_w": 450,
"thumb_src_h": 449,
"src_w": 600,
"src_h": 599
},
"image_id": 1993,
"is_downloadable": false,
"is_in_stock": true,
"is_purchasable": true,
"is_sold_individually": "no",
"is_virtual": false,
"max_qty": "",
"min_qty": 1,
"price_html": "<span class=\"price\"><span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">£</span>20.00</bdi></span></span>",
"sku": "woo-vneck-tee-red",
"variation_description": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.</p>\n",
"variation_id": 1982,
"variation_is_active": true,
"variation_is_visible": true,
"weight": "",
"weight_html": "N/A"
},
{
"attributes": {
"attribute_pa_color": "green",
"attribute_pa_size": ""
},
"availability_html": "",
"backorders_allowed": false,
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"dimensions_html": "N/A",
"display_price": 20,
"display_regular_price": 20,
"image": {
"title": "vnech-tee-green-1.jpg",
"caption": "",
"url": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1.jpg",
"alt": "",
"src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-600x600.jpg",
"srcset": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-600x600.jpg 600w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-450x450.jpg 450w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-100x100.jpg 100w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-300x300.jpg 300w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-80x80.jpg 80w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-768x768.jpg 768w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1.jpg 800w",
"sizes": "(max-width: 600px) 100vw, 600px",
"full_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1.jpg",
"full_src_w": 800,
"full_src_h": 800,
"gallery_thumbnail_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-100x100.jpg",
"gallery_thumbnail_src_w": 100,
"gallery_thumbnail_src_h": 100,
"thumb_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-green-1-450x450.jpg",
"thumb_src_w": 450,
"thumb_src_h": 450,
"src_w": 600,
"src_h": 600
},
"image_id": 1994,
"is_downloadable": false,
"is_in_stock": true,
"is_purchasable": true,
"is_sold_individually": "no",
"is_virtual": false,
"max_qty": "",
"min_qty": 1,
"price_html": "<span class=\"price\"><span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">£</span>20.00</bdi></span></span>",
"sku": "woo-vneck-tee-green",
"variation_description": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.</p>\n",
"variation_id": 1983,
"variation_is_active": true,
"variation_is_visible": true,
"weight": "",
"weight_html": "N/A"
},
{
"attributes": {
"attribute_pa_color": "blue",
"attribute_pa_size": ""
},
"availability_html": "",
"backorders_allowed": false,
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"dimensions_html": "N/A",
"display_price": 15,
"display_regular_price": 15,
"image": {
"title": "vnech-tee-blue-1.jpg",
"caption": "",
"url": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1.jpg",
"alt": "",
"src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-600x600.jpg",
"srcset": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-600x600.jpg 600w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-450x450.jpg 450w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-100x100.jpg 100w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-300x300.jpg 300w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-80x80.jpg 80w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-768x768.jpg 768w, http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1.jpg 800w",
"sizes": "(max-width: 600px) 100vw, 600px",
"full_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1.jpg",
"full_src_w": 800,
"full_src_h": 800,
"gallery_thumbnail_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-100x100.jpg",
"gallery_thumbnail_src_w": 100,
"gallery_thumbnail_src_h": 100,
"thumb_src": "http://localhost/xampp/wp/wp-content/uploads/2020/09/vnech-tee-blue-1-450x450.jpg",
"thumb_src_w": 450,
"thumb_src_h": 450,
"src_w": 600,
"src_h": 600
},
"image_id": 1995,
"is_downloadable": false,
"is_in_stock": true,
"is_purchasable": true,
"is_sold_individually": "no",
"is_virtual": false,
"max_qty": "",
"min_qty": 1,
"price_html": "<span class=\"price\"><span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">£</span>15.00</bdi></span></span>",
"sku": "woo-vneck-tee-blue",
"variation_description": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.</p>\n",
"variation_id": 1984,
"variation_is_active": true,
"variation_is_visible": true,
"weight": "",
"weight_html": "N/A"
}
]
I can see that first has:
"attributes": {
"attribute_pa_color": "red",
"attribute_pa_size": ""
Why is size attribute empty and how can I know that this product has following variations?
color: red, green, blue
size: small, medium, large
How
