RemoveCouponFromCartMutation
Description
Removes a previously applied coupon code from the cart. This mutation allows you to cancel a discount that was applied using the applyCouponToCart mutation.
Endpoint
mutation removeCouponFromCart($cartId: String!, $couponCode: String!) {
removeCouponFromCart(cartId: $cartId, couponCode: $couponCode) {
# Return fields
}
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| cartId | String | Yes | The unique identifier of the cart from which the coupon will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations. |
| couponCode | String | Yes | The coupon code to remove from the cart. This should match the code that was previously applied. |
Return Values
The mutation returns a CartType object with the following structure:
| Field | Type | Description |
|---|---|---|
| billing_address | Object | The billing address associated with the cart. |
| shipping_address | Object | The shipping address associated with the cart. |
| items | [CartItem] | Array of items in the cart. |
| selected_shipping_method | Object | The selected shipping method for the cart. |
| selected_payment_method | Object | The selected payment method for the cart. |
| totals | Object | Cart totals information, with any discounts from the removed coupon no longer applied. |
For detailed information about the structure of these fields, refer to the CartQuery documentation.
Usage Example
mutation {
removeCouponFromCart(
cartId: "abc123",
couponCode: "DISCOUNT10"
) {
items {
id
quantity
name
row_total {
value
currency
}
}
totals {
grand_total {
value
currency
}
discount_amount {
value
currency
}
}
}
}
Example Response
{
"data": {
"removeCouponFromCart": {
"items": [
{
"id": "123",
"quantity": 2,
"name": "Sample Product",
"row_total": {
"value": 39.98,
"currency": "USD"
}
}
],
"totals": {
"grand_total": {
"value": 39.98,
"currency": "USD"
},
"discount_amount": {
"value": 0,
"currency": "USD"
}
}
}
}
}
Notes
- If the coupon code is not currently applied to the cart, an error may be thrown.
- After removing a coupon, the cart totals will be recalculated without the discount.
- You can apply a different coupon to the cart after removing the current one by using the
applyCouponToCartmutation. - This mutation requires the exact coupon code that was previously applied to the cart.