Skip to main content
Version: 2.0.0

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

ArgumentTypeRequiredDescription
cartIdStringYesThe unique identifier of the cart from which the coupon will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations.
couponCodeStringYesThe 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:

FieldTypeDescription
billing_addressObjectThe billing address associated with the cart.
shipping_addressObjectThe shipping address associated with the cart.
items[CartItem]Array of items in the cart.
selected_shipping_methodObjectThe selected shipping method for the cart.
selected_payment_methodObjectThe selected payment method for the cart.
totalsObjectCart 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 applyCouponToCart mutation.
  • This mutation requires the exact coupon code that was previously applied to the cart.