This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

removeCouponFromCart mutation

The removeCouponFromCart mutation removes a previously-applied coupon from the cart. The cart must contain at least one item in order to remove the coupon.

Syntax

mutation: {removeCouponFromCart(input: RemoveCouponFromCartInput) {RemoveCouponFromCartOutput}}

Example usage

The following example removes a coupon from the cart.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mutation {
  removeCouponFromCart(
    input:
      { cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG" }
    ) {
    cart {
      items {
        product {
          name
        }
        quantity
      }
      applied_coupons {
        code
      }
      prices {
        grand_total{
          value
          currency
        }
      }
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
  "data": {
    "removeCouponFromCart": {
      "cart": {
        "items": [
          {
            "product": {
              "name": "Strive Shoulder Pack"
            },
            "quantity": 1
          },
          {
            "product": {
              "name": "Affirm Water Bottle "
            },
            "quantity": 1
          }
        ],
        "applied_coupons": null,
        "prices": {
          "grand_total": {
            "value": 39,
            "currency": "USD"
          }
        }
      }
    }
  }
}

Input attributes

The removeCouponFromCart mutation must contain the following attribute:

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart

Output attributes

The removeCouponFromCart mutation returns the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
id ID! The ID of the cart
is_virtual Boolean! Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.

Errors

Error Description
Cart does not contain products. The coupon cannot be removed from the empty cart.
Could not find a cart with ID "XXX" The specified cart_id value does not exist in the quote_id_mask table.
Current user does not have an active cart. The user cannot perform this mutation on the inactive cart.
Required parameter "cart_id" is missing The required cart_id argument contains an empty value.
The coupon code couldn't be deleted. Verify the coupon code and try again. The coupon was not removed from the cart. Check the existing shopping cart price rules for details.
The current user cannot perform operations on cart XXX An unauthorized user (guest) tried to add the product into a customer’s cart, or an authorized user (customer) tried to add the product into the cart of another customer.
Wrong store code specified for cart The specified cart_id does not exist in specified store.