Skip to content

[8.0] Allow negative values for WC_Fee again to support custom discounts. #1009

Open
@gtconceptstim

Description

@gtconceptstim

Since version 8.0, the Mollie WooCommerce integration no longer allows negative values in WC_Fee line items. This change has broken many custom plugins and solutions where developers use negative fees to apply dynamic discounts.

Problem Statement
Previously, WooCommerce allowed developers to add negative fees using the WC_Fee class. This approach is widely used to create dynamic and automated discounts without relying on coupons. For example:

  • Loyalty Discounts: Automatically apply a fixed or percentage discount based on the customer's loyalty status.
  • Custom Promotions: Apply conditional discounts when specific products are in the cart.
  • Dynamic Pricing Rules: Create discounts based on quantity, customer group, or time of day.

However, since version 8.0, Mollie now rejects these negative fees with the following error:
Error executing API call (422: Unprocessable Entity): Line item 3 is invalid. The 'unitPrice' field cannot be negative, unless the 'type' is one of the following: 'discount', 'store_credit', and 'gift_card'.

Why this change is problematic
The add_fee() function in WooCommerce does not support specifying a type like discount, so any negative value results in an error during checkout when using Mollie. This is particularly problematic because:

  • Developer Flexibility: Many WooCommerce developers, including myself, have implemented numerous custom plugins for clients that rely on negative WC_Fee for discounts.
  • Loss of Intuitive Discount Handling: Using WC_Fee is an intuitive and clean way to add or subtract amounts from the order total.
  • Inefficient Workarounds: To bypass this issue, we now have to programmatically create and apply coupons, which is cumbersome and not ideal for automated or complex discount scenarios.

In every other version of the woocommerce intergation this was not a problem at all. Would you all be so kind take a look at this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions