Complete guide to subscription management mutations - cancel, reactivate, switch, update, and change payment methods.
WooGraphQL Pro provides mutations for complete subscription lifecycle management and subscription product CRUD.
Marks an active subscription for cancellation. The subscription will be cancelled at the end of the current billing period.
| Field | Type | Required | Description |
|---|---|---|---|
id | Int! | Yes | Subscription database ID |
Returns the updated Subscription object.
mutation CancelSubscription($id: Int!) { cancelSubscription(input: { id: $id }) { subscription { id databaseId status cancelledDate endDate } } }
Variables:
{ "id": 123 }
Response:
{ "data": { "cancelSubscription": { "subscription": { "id": "c3Vic2NyaXB0aW9uOjEyMw==", "databaseId": 123, "status": "PENDING_CANCEL", "cancelledDate": "2024-01-15T10:30:00+00:00", "endDate": "2024-02-15T10:30:00+00:00" } } } }
PENDING_CANCELendDateRestores a cancelled or pending-cancel subscription to active status.
| Field | Type | Required | Description |
|---|---|---|---|
id | Int! | Yes | Subscription database ID |
Returns the updated Subscription object.
mutation ReactivateSubscription($id: Int!) { reactivateSubscription(input: { id: $id }) { subscription { id status nextPaymentDate } } }
Variables:
{ "id": 123 }
Response:
{ "data": { "reactivateSubscription": { "subscription": { "id": "c3Vic2NyaXB0aW9uOjEyMw==", "status": "ACTIVE", "nextPaymentDate": "2024-02-15T10:30:00+00:00" } } } }
ACTIVESwitches a subscription to a different product, with automatic proration calculation.
| Field | Type | Required | Description |
|---|---|---|---|
subscriptionId | Int! | Yes | Current subscription database ID |
lineItemId | Int! | Yes | Line item to switch |
productId | Int! | Yes | New product/variation database ID |
Returns the Cart with the switch item and proration details.
mutation SwitchSubscription( $subscriptionId: Int! $lineItemId: Int! $productId: Int! ) { switchSubscription( input: { subscriptionId: $subscriptionId lineItemId: $lineItemId productId: $productId } ) { cart { contents { nodes { key product { node { name } } quantity total extraData { key value } } } total } cartItem { key extraData { key value } } } }
Variables:
{ "subscriptionId": 123, "lineItemId": 456, "productId": 789 }
The cart item's extraData contains switch metadata:
| Key | Description |
|---|---|
subscription_switch | Switch details JSON |
subscription_switch_data | Proration calculations |
The switch calculates prorated amounts based on:
Updates subscription details including billing address.
| Field | Type | Required | Description |
|---|---|---|---|
id | Int! | Yes | Subscription database ID |
billing | CustomerAddressInput | No | Billing address fields |
| Field | Type | Description |
|---|---|---|
firstName | String | First name |
lastName | String | Last name |
company | String | Company name |
address1 | String | Address line 1 |
address2 | String | Address line 2 |
city | String | City |
state | String | State/Province |
postcode | String | Postal code |
country | String | Country code |
email | String | Email address |
phone | String | Phone number |
Returns the updated Subscription object.
mutation UpdateSubscription($id: Int!, $billing: CustomerAddressInput) { updateSubscription(input: { id: $id, billing: $billing }) { subscription { id billing { firstName lastName address1 city state postcode country email phone } } } }
Variables:
{ "id": 123, "billing": { "firstName": "Jane", "lastName": "Smith", "address1": "456 New Street", "city": "New City", "state": "CA", "postcode": "90210", "country": "US", "email": "[email protected]", "phone": "555-0123" } }
Sets a subscription's recurring payment method to one of the customer's saved payment tokens. The token must already exist (added via the customer's account / add-payment-method flow) and belong to the subscription's customer.
| Field | Type | Required | Description |
|---|---|---|---|
id | ID! | Yes | Subscription database ID or global ID |
paymentTokenId | Int! | Yes | Database ID of the customer's saved WC_Payment_Token to set on the subscription |
| Field | Type | Description |
|---|---|---|
subscription | Subscription | The subscription with its updated payment method |
mutation ChangePaymentMethod($id: ID!, $paymentTokenId: Int!) { changePaymentMethod(input: { id: $id, paymentTokenId: $paymentTokenId }) { subscription { id paymentMethod paymentMethodTitle } } }
WCS_Payment_Tokens::update_subscription_token(), which swaps only the single gateway meta key whose value matches the subscription's current source (resolved via the woocommerce_subscription_payment_meta filter). Account-scoped meta such as a gateway customer id is left untouched, and no gateway-specific keys cross the wire.pm_) — so the correct key can still be located and swapped.Resubscribes to a cancelled or expired subscription by adding its items to the cart for checkout (mirrors the WCS_Cart_Resubscribe flow). The current cart is emptied first.
| Field | Type | Required | Description |
|---|---|---|---|
id | ID! | Yes | Subscription database ID or global ID |
Returns the cart populated with the resubscription items.
mutation Resubscribe($id: ID!) { resubscribe(input: { id: $id }) { cart { contents { nodes { key product { node { name } } quantity } } total } } }
wcs_can_user_resubscribe_to passes — the subscription is cancelled/expired, has previous payments, and all products are still available.subscription_resubscribe extra data linking it to the original subscription and line item.checkout mutation against the populated cart.See the Mutations Reference for the full specification.
All subscription mutations require:
Common errors:
| Error | Cause |
|---|---|
Subscription not found | Invalid subscription ID |
Not authorized | User doesn't own the subscription |
Invalid subscription status | Operation not allowed for current status |
Switch not allowed | Subscription settings prevent switching |
Creates a new subscription product with recurring billing fields. See the Mutations Reference for full input/output details.
mutation CreateSubscriptionProduct($input: CreateSubscriptionProductInput!) { createSubscriptionProduct(input: $input) { product { databaseId name ... on SubscriptionProduct { price subscriptionPeriod subscriptionPeriodInterval subscriptionLength trialPeriod trialLength signUpFee } } } }
Variables:
{ "input": { "name": "Monthly Pro Plan", "subscriptionPrice": 29.99, "subscriptionPeriod": "MONTH", "subscriptionPeriodInterval": 1, "subscriptionLength": 0, "signUpFee": 9.99, "trialPeriod": "WEEK", "trialLength": 1 } }
Updates an existing subscription product.
mutation UpdateSubscriptionProduct($input: UpdateSubscriptionProductInput!) { updateSubscriptionProduct(input: $input) { product { databaseId ... on SubscriptionProduct { subscriptionPrice subscriptionPeriod } } } }
Subscription product mutations also accept addons and excludeGlobalAddons fields. See Per-Product Addon Fields.