Personalized checkout and custom promotions with Shopify Scripts
How can I check the colors that are already selected in the product?
For my query I am using getProduct followed by
productByHandle
My query:
Reuslt:
Color Admin:
Hi @ViniciusGG
I am from Mageplaza - Shopify solution expert.
With your current query, you aren't fetching the selected colors for each variant yet because:
You need to update your query by adding selectedOptions inside node, like this:
variants(first: 5) {
edges {
node {
id
title
price {
amount
currencyCode
}
availableForSale
selectedOptions {
name
value
}
}
}
}
Specifically, you need to:
Example of the response after adding selectedOptions:
{
"data": {
"productByHandle": {
"variants": {
"edges": [
{
"node": {
"id": "...",
"title": "Red Shirt",
"selectedOptions": [
{ "name": "Color", "value": "Red" },
{ "name": "Size", "value": "M" }
]
}
},
{
"node": {
"id": "...",
"title": "Blue Shirt",
"selectedOptions": [
{ "name": "Color", "value": "Blue" },
{ "name": "Size", "value": "L" }
]
}
}
]
}
}
}
}
=> This way, you can easily tell that the product has the colors Red and Blue.
Please let me know if it works as expected!
Best regards!
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025