• Resolved lukecb

    (@lukecb)


    Woocommerce shows the discount applied to the order, but when calling through the rest of the api it is 0 in coupon_lines. Only for some orders

    "discount_total": "150.00",
    "discount_tax": "0.00"

    "coupon_lines": [
    {
    "id": 3325,
    "code": "domi15",
    "discount": "0",
    "discount_tax": "0",
    "meta_data": [
    {
    "id": 31333,
    "key": "coupon_info",
    "value": "[11910,\"domi15\",\"percent\",15]",
    "display_key": "coupon_info",
    "display_value": "[11910,\"domi15\",\"percent\",15]"
    }
    ],
    "discount_type": "percent",
    "nominal_amount": 15,
    "free_shipping": false
    }
    ],

    Thank your help Lukas

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there,

    Thanks for the additional details.

    It looks like your site is using the newer coupon metadata format introduced in WooCommerce 8.7. In this version, WooCommerce replaced the old coupon_data entries with a lighter coupon_info format to improve performance and database size.

    This change also affected how coupon information appears in the REST API. For more details you can use this guide. https://developer.woocommerce.com/2024/02/08/changes-in-order-coupons-line-item-storage/

    To assist you further, Could you please confirm whether the discount was applied manually or through the coupon field at checkout?

    Also, for the orders where the REST API is showing a 0 discount value, was the coupon code entered in uppercase or lowercase?

    This information will help us better understand what’s happening.

    Thread Starter lukecb

    (@lukecb)

    The coupon was entered directly in the cart by the customer.

    I don’t know what letters the customer entered the coupon in. The system automatically always converts it to lowercase, even if the customer enters it in uppercase.

    Hi @lukecb,

    Thank you for getting back to me and for the clarification. I’d like us to take a step back to better understand what you need help with.

    Are you looking for support with the coupon-related API issues, or are your customers having trouble using coupons? I ask because your initial message focused on the API, but the conversation seems to have shifted toward customers experiencing issues applying coupons in the cart. However, I didn’t see any specific details about this in your original message.

    Could you please confirm the exact problem your customers are facing when trying to use coupons in the cart or at checkout?

    From my understanding it seems you meant the coupon usage by the customer was successful but when calling the coupon details via API you’re getting 0 which means the coupon hasn’t been used.

    If so, can you confirm how you knew the coupon has been used successfully?

    Thread Starter lukecb

    (@lukecb)

    On the customer and sales side, the amount and discount are displayed correctly.

    We call the value to accounting via REST API and sometimes zero is displayed there, see first post.

    Thank you

    Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @lukecb,

    Thanks so much for clarifying that. It’s helpful to know that the discount displays correctly in the WooCommerce dashboard and on the customer-facing side, but the REST API is sometimes returning 0 in the coupon_lines section for accounting purposes.

    To take a closer look at what might be causing this, could you please share your System Status Report? You can find it by going to WooCommerce → Status and clicking the Get system report button. Once generated, you can copy the contents and paste them into https://pastebin.com or https://gist.github.com and share the link here.

    This will help us review your current setup and plugin versions to better understand any potential causes.

    Thread Starter lukecb

    (@lukecb)

    I send: https://pastebin.com/k23iffcV

    Thank you

    Hi @lukecb,

    Thanks for providing the system status update. Just to confirm – since you’re able to call the API and receive responses, the API itself appears to be functioning properly. However, I see you’re experiencing an issue where the coupon usage count shows 0 for the “domi15” coupon, even though you mentioned it has been used.

    Could you please provide some additional details:

    1. How was this coupon applied – did a customer use it during checkout, or was it manually applied by an administrator to an order?
    2. Would you be able to share a screenshot showing the order details that include this coupon usage? You can upload the image to snipboard.io for easy sharing.

    This information will help us better understand the discrepancy between the expected and actual usage counts.

    Thread Starter lukecb

    (@lukecb)

    Hi,

    The coupon was used by the customer in the cart.

    Some orders have it right. This is an example that has 0 in the REST API 22521025:

    https://snipboard.io/ce3QUJ.jpg

    REST API:

    https://snipboard.io/0batkI.jpg

    Thanks

    Hi @lukecb,

    Thank you for getting back to us and for providing the requested details. Based on what you’ve shared, I can confirm the coupon does appear in the order details. It also seems you’re pulling the coupon data directly via coupon endpoint.

    Just to clarify, when pulling coupon data via the REST API using the endpoint GET /wp-json/wc/v3/coupons, the discount and discount_tax fields will always show as 0. This is expected because those fields only reflect values when a coupon is applied to an order — and that data is only available through the order endpoint.

    • discount represents the actual amount discounted in a specific order.
    • discount_tax is the amount of tax reduced as a result of the discount.

    Since the /coupons endpoint only returns the coupon’s general information (not how it’s used in orders), these values remain zero.

    To see actual usage data, you’d need to pull it from an order that used the coupon, for example:

    GET /wp-json/wc/v3/orders/1234

    In the order response, you’ll see something like:

    "coupon_lines": [
      {
        "code": "SUMMER15",
        "discount": "15.00",
        "discount_tax": "1.50"
      }
    ]

    These values are specific to that order and won’t be present when pulling the coupon directly.

    Let me know if you need any further clarification.

    Thread Starter lukecb

    (@lukecb)

    That 0 is displayed when calling the order

    https://elabela.cz/wp-json/wc/v3/orders/6977/?

    "discount_total": "150.00",
    "discount_tax": "0.00"

    "coupon_lines": [
    {
    "id": 3325,
    "code": "domi15",
    "discount": "0",
    "discount_tax": "0",
    "meta_data": [

    {
    "id": 31333,
    "key": "coupon_info",
    "value": "[11910,\"domi15\",\"percent\",15]",
    "display_key": "coupon_info",
    "display_value": "[11910,\"domi15\",\"percent\",15]"
    }
    ],
    "discount_type": "percent",
    "nominal_amount": 15,
    "free_shipping": false
    }
    ],

    Hi @lukecb,

    Thanks for getting back and for the clarification. I reviewed your initial message and noticed you mentioned that some orders are pulled correctly while others are not. This suggests there may be inconsistencies or conditions tied to coupon usage and tax settings on your site.

    Since you’re receiving a response, the API itself appears to be functioning properly. However, inconsistent data likely stems from how coupons and taxes are configured on your store. Troubleshooting this type of issue would require direct access to your site, which we can’t do, as requesting login credentials goes beyond the scope of forum support.

    I recommend reaching out to a WooCommerce expert via a platform like codeable.io for a more in-depth inspection.

    Plugin Support Chris Moreira – a11n

    (@chrism245)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    If you have a few minutes, we’d love if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/

    Plugin Support Chris Moreira – a11n

    (@chrism245)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    If you have a few minutes, we’d love if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘REST API – coupon_lines discount 0’ is closed to new replies.