활용 가이드WooCommerce
WooCommerce
WooCommerce 확장 기능을 사용하면 GraphQL을 통해 WooCommerce 상품 데이터를 가져올 수 있습니다.
WooCommerce 상품 타입
필드 woocommerceProducts는 WooCommerceProductUnion 타입을 반환하며, 4가지 가능한 상품 타입으로 구성됩니다.
WooCommerceSimpleProductWooCommerceExternalProductWooCommerceGroupProductWooCommerceVariableProduct
각 타입에 따라 쿼리할 수 있는 필드가 달라집니다.
WooCommerce 상품 인터페이스
2개의 서로 다른 상품 타입(및 상품 변형)이 일부 필드를 공유할 수 있으므로, 이 필드들은 각 상품 타입이 구현할 수도 있고 하지 않을 수도 있는 인터페이스에 추가되었습니다.
예를 들어, Shippable은 배송을 지원하는 상품, Priceable은 가격이 있는 상품(변형 상품에는 price 필드가 없으며 변형을 통해 제공됩니다), Taxable은 세금 설정을 지원하는 상품 등입니다.
| 인터페이스 | 설명 |
|---|---|
WooCommerceProduct | 모든 상품 타입이 공유하는 필드 (즉, 4개 타입 모두에서 구현) |
WooCommerceProductOrProductVariation | 모든 상품 타입 및 상품 변형이 공유하는 필드 |
WooCommerceCrossSellableProduct | "교차 판매" 상품 정의를 지원하는 상품 |
WooCommerceDownloadableProductOrProductVariation | 다운로드 가능한 파일을 지원하는 상품 (및 상품 변형) |
WooCommercePriceableProductOrProductVariation | price 필드가 있는 상품 (및 상품 변형) |
WooCommerceShippableProductOrProductVariation | 배송 설정을 지원하는 상품 (및 상품 변형) |
WooCommerceTaxableProduct | 세금 설정을 지원하는 상품 |
WooCommerceWithStockManagementProductOrProductVariation | 재고 관리를 지원하는 상품 (및 상품 변형) |
상품 데이터 가져오기
다음 쿼리는 모든 상품 타입의 데이터를 가져오며, 각 상품 타입의 모든 필드를 쿼리합니다.
query FetchWooCommerceData
{
# Single product by ID
productByID: woocommerceProduct(by: { id: 43 }) {
__typename
...WooCommerceSimpleProductFields
...WooCommerceGroupProductFields
...WooCommerceExternalProductFields
...WooCommerceVariableProductFields
}
# Single product by slug
productBySlug: woocommerceProduct(by: { slug: "iphone-15-pro" }) {
__typename
id
name
slug
url
urlPath
sku
}
# Single product by SKU
productBySku: woocommerceProduct(by: { sku: "IPHONE15PRO" }) {
__typename
id
name
slug
url
urlPath
sku
}
# List of products
woocommerceProducts {
__typename
...WooCommerceSimpleProductFields
...WooCommerceGroupProductFields
...WooCommerceExternalProductFields
...WooCommerceVariableProductFields
}
woocommerceProductsCount
}
# ----------------------------------------------------------------------
# Fragments
# ----------------------------------------------------------------------
fragment WooCommerceSimpleProductFields on WooCommerceSimpleProduct {
# Specific fields for this type
# (empty)
# Common fields
...WooCommerceProductOrProductVariationInterfaceFields
...WooCommerceIdentifiableObjectInterfaceFields
...WooCommerceProductInterfaceFields
...WooCommerceCrossSellableProductInterfaceFields
...WooCommerceDownloadableProductOrProductVariationInterfaceFields
...WooCommercePriceableProductOrProductVariationInterfaceFields
...WooCommerceShippableProductOrProductVariationInterfaceFields
...WooCommerceTaxableProductInterfaceFields
...WooCommerceWithStockManagementProductOrProductVariationInterfaceFields
}
fragment WooCommerceGroupProductFields on WooCommerceGroupProduct {
# Specific fields for this type
hasChildren
childrenCount
minPrice
maxPrice
minPriceFormatted
maxPriceFormatted
children {
id
name
slug
sku
}
# Common fields
...WooCommerceProductOrProductVariationInterfaceFields
...WooCommerceIdentifiableObjectInterfaceFields
...WooCommerceProductInterfaceFields
}
fragment WooCommerceExternalProductFields on WooCommerceExternalProduct {
# Specific fields for this type
externalURL
buttonText
# Common fields
...WooCommerceProductOrProductVariationInterfaceFields
...WooCommerceIdentifiableObjectInterfaceFields
...WooCommerceProductInterfaceFields
...WooCommercePriceableProductOrProductVariationInterfaceFields
...WooCommerceTaxableProductInterfaceFields
}
fragment WooCommerceVariableProductFields on WooCommerceVariableProduct {
# Specific fields for this type
hasVariations
variationsCount
minPrice
maxPrice
minRegularPrice
maxRegularPrice
minSalePrice
maxSalePrice
priceRange
variations {
id
name
slug
sku
}
defaultAttributes {
taxonomy
termSlug
termObject {
id
name
slug
}
}
# Common fields
...WooCommerceProductOrProductVariationInterfaceFields
...WooCommerceIdentifiableObjectInterfaceFields
...WooCommerceProductInterfaceFields
...WooCommerceCrossSellableProductInterfaceFields
...WooCommerceTaxableProductInterfaceFields
}
# Interfaces
# ----------------------------------------------------------------------
fragment WooCommerceCrossSellableProductInterfaceFields on WooCommerceCrossSellableProduct {
crossSellIDs
crossSells {
id
name
slug
sku
}
}
fragment WooCommerceDownloadableProductOrProductVariationInterfaceFields on WooCommerceDownloadableProductOrProductVariation {
isDownloadable
downloadLimit
downloadExpiry
downloads
downloadsCount
}
fragment WooCommercePriceableProductOrProductVariationInterfaceFields on WooCommercePriceableProductOrProductVariation {
price
priceFormatted
regularPrice
regularPriceFormatted
salePrice
salePriceFormatted
onSale
dateOnSaleFrom
dateOnSaleFromStr
formattedDateOnSaleFromStr: dateOnSaleFromStr(format: "d/m/Y H:i:s")
dateOnSaleTo
dateOnSaleToStr
formattedDateOnSaleToStr: dateOnSaleToStr(format: "d/m/Y H:i:s")
}
fragment WooCommerceShippableProductOrProductVariationInterfaceFields on WooCommerceShippableProductOrProductVariation {
isVirtual
weight
length
width
height
dimensions
shippingClassID
shippingClass {
id
name
slug
description
count
}
}
fragment WooCommerceTaxableProductInterfaceFields on WooCommerceTaxableProduct {
taxStatus
taxClass
}
fragment WooCommerceWithStockManagementProductOrProductVariationInterfaceFields on WooCommerceWithStockManagementProductOrProductVariation {
manageStock
stockQuantity
stockStatus
backorders
backordersAllowed
backordered
soldIndividually
lowStockThreshold
}
fragment WooCommerceProductOrProductVariationInterfaceFields on WooCommerceProductOrProductVariation {
name
description
shortDescription
sku
globalUniqueID
isPurchasable
image {
id
src
altText
title
caption
}
imageID
catalogVisibility
status
date
dateStr
formattedDateStr: dateStr(format: "d/m/Y H:i:s")
modifiedDate
modifiedDateStr
formattedModifiedDateStr: modifiedDateStr(format: "d/m/Y H:i:s")
}
fragment WooCommerceIdentifiableObjectInterfaceFields on IdentifiableObject {
id
}
fragment WooCommerceProductInterfaceFields on WooCommerceProduct {
url
urlPath
slug
featured
totalSales
reviewsAllowed
averageRating
ratingCount
upsellIDs
upsells {
id
name
slug
sku
}
upsellsCount
crossSellsCount
purchaseNote
menuOrder
type
isVisible
categories {
id
name
slug
}
categoriesCount
tags {
id
name
slug
}
tagsCount
brands {
id
name
slug
}
brandsCount
galleryImages {
id
src
altText
title
caption
}
galleryImagesCount
attributes {
name
taxonomyObject {
id
name
slug
options {
id
name
slug
}
}
options
optionTaxonomyTermObjects {
id
name
slug
}
position
isVisible
isVariation
isTaxonomy
}
reviews {
id
content
author
}
reviewsCount
}특정 상품 타입 쿼리하기
필드 woocommerceProducts에서 상품 타입을 필터링하여 특정 상품 타입을 쿼리할 수 있습니다.
query FilterProductsByType {
woocommerceProducts(filter: { types: [simple, external, variable] }) {
__typename
... on WooCommerceProduct {
id
name
sku
}
... on WooCommercePriceableProductOrProductVariation {
price
}
}
woocommerceProductsCount(filter: { types: [simple, external, variable] })
}또는 해당 타입에 대응하는 필드를 사용할 수도 있습니다.
woocommerceSimpleProductandwoocommerceSimpleProductswoocommerceExternalProductandwoocommerceExternalProductswoocommerceGroupProductandwoocommerceGroupProductswoocommerceVariableProductandwoocommerceVariableProducts
단순 상품
이 쿼리는 단순 상품의 데이터를 가져옵니다.
query FetchSimpleProducts {
woocommerceSimpleProducts {
__typename
id
name
sku
}
woocommerceSimpleProductsCount
}외부 상품
이 쿼리는 외부 URL과 버튼 텍스트를 포함한 외부 상품의 데이터를 가져옵니다.
query FetchExternalProducts {
woocommerceExternalProducts {
__typename
id
name
sku
externalURL
buttonText
}
woocommerceExternalProductsCount
}그룹 상품
이 쿼리는 하위 상품을 포함한 그룹 상품의 데이터를 가져옵니다.
query FetchGroupProducts {
woocommerceGroupProducts {
__typename
id
name
sku
children {
id
name
}
childrenCount
}
woocommerceGroupProductsCount
}가변 상품
이 쿼리는 변형을 포함한 가변 상품의 데이터를 가져옵니다.
query FetchVariableProducts {
woocommerceVariableProducts {
__typename
id
name
sku
variations {
id
name
price
}
variationsCount
}
woocommerceVariableProductsCount
}가변 상품의 경우 변형을 직접 쿼리할 수도 있습니다.
query GetProductVariations {
woocommerceProductVariations {
id
name
sku
price
parent {
id
name
sku
}
priceFormatted
regularPrice
regularPriceFormatted
salePrice
salePriceFormatted
stockStatus
stockQuantity
attributes {
taxonomy
termSlug
termObject {
id
name
slug
}
}
}
}필터를 사용한 쿼리
다양한 기준으로 상품을 필터링하고 정렬하며 페이지네이션할 수 있습니다.
query GetFilteredProducts {
woocommerceProducts(pagination: { limit: -1 }, filter: {
types: [simple, external],
visibility: visible,
categoriesBy: { ids: [81] },
tagsBy: { slugs: ["apple"] },
}) {
id
name
status
type
isVisible
catalogVisibility
categories(sort: { by: ID, order: DESC }) {
id
name
slug
}
tags {
id
name
slug
}
}
}Prev
Next