Loading…
Loading…
Query and display subscription products with recurring billing fields, trial periods, and sign-up fees.
WooGraphQL Pro extends the product schema with subscription-specific types and fields.
Simple subscription products with fixed recurring billing.
query GetSubscriptionProduct($id: ID!) { product(id: $id, idType: DATABASE_ID) { ... on SubscriptionProduct { id databaseId name slug description shortDescription # Pricing price regularPrice salePrice subscriptionPrice # Billing Schedule subscriptionPeriod subscriptionPeriodInterval subscriptionLength # Sign-up subscriptionSignUpFee # Trial subscriptionTrialLength subscriptionTrialPeriod # Standard product fields image { sourceUrl } galleryImages { nodes { sourceUrl } } } } }
Variable subscription products with multiple pricing options.
query GetVariableSubscription($id: ID!) { product(id: $id, idType: DATABASE_ID) { ... on VariableSubscription { id name price subscriptionPrice # Variations variations { nodes { id databaseId name price subscriptionPrice subscriptionPeriod subscriptionPeriodInterval attributes { nodes { name value } } } } # Attributes for selection attributes { nodes { name options variation } } } } }
| Field | Type | Description |
|---|---|---|
price | String | Formatted price with billing schedule |
regularPrice | String | Regular price |
salePrice | String | Sale price (if on sale) |
subscriptionPrice | String | Recurring payment amount |
| Field | Type | Description |
|---|---|---|
subscriptionPeriod | String | Billing period: day, week, month, year |
subscriptionPeriodInterval | Int | Interval between billings (e.g., 2 for bi-monthly) |
subscriptionLength | Int | Number of billing periods (0 = unlimited) |
| Field | Type | Description |
|---|---|---|
subscriptionSignUpFee | String | One-time sign-up fee |
subscriptionTrialLength | Int | Trial period length |
subscriptionTrialPeriod | String | Trial period unit: day, week, month, year |
Products that support subscription functionality implement this interface:
interface ProductWithSubscription { subscriptionPrice: String subscriptionPeriod: String subscriptionPeriodInterval: Int subscriptionLength: Int subscriptionSignUpFee: String subscriptionTrialLength: Int subscriptionTrialPeriod: String }
query GetSubscriptionProducts($first: Int = 12) { products(first: $first, where: { type: SUBSCRIPTION }) { nodes { ... on SubscriptionProduct { id name price subscriptionPeriod subscriptionPeriodInterval image { sourceUrl } } } } }
query GetVariableSubscriptions($first: Int = 12) { products(first: $first, where: { type: VARIABLE_SUBSCRIPTION }) { nodes { ... on VariableSubscription { id name price variations(first: 100) { nodes { id price subscriptionPeriod } } } } } }
Subscription prices typically display as:
$10.00 / month - Monthly subscription$25.00 every 2 months - Bi-monthly subscription$100.00 / year for 2 years - Annual subscription with end date$50.00 / month with a 14-day free trial - With trial$99.00 sign-up fee then $10.00 / month - With sign-up feefunction formatSubscriptionPrice(product: SubscriptionProduct): string { let price = product.subscriptionPrice; let period = product.subscriptionPeriod; let interval = product.subscriptionPeriodInterval; // Base price let display = `${price}`; // Period if (interval === 1) { display += ` / ${period}`; } else { display += ` every ${interval} ${period}s`; } // Length if (product.subscriptionLength > 0) { display += ` for ${product.subscriptionLength} ${period}s`; } // Trial if (product.subscriptionTrialLength > 0) { display += ` with a ${product.subscriptionTrialLength}-${product.subscriptionTrialPeriod} free trial`; } // Sign-up fee if (product.subscriptionSignUpFee) { display = `${product.subscriptionSignUpFee} sign-up fee then ${display}`; } return display; }
Subscription products are added to cart like regular products:
mutation AddSubscriptionToCart($productId: Int!, $quantity: Int = 1) { addToCart(input: { productId: $productId, quantity: $quantity }) { cart { contents { nodes { key product { node { name } } quantity total } } total } } }
For variable subscriptions, include the variation:
mutation AddVariableSubscriptionToCart( $productId: Int! $variationId: Int! $quantity: Int = 1 ) { addToCart( input: { productId: $productId variationId: $variationId quantity: $quantity } ) { cart { contents { nodes { key quantity total } } total } } }