woothemes/woocommerce — pull request #4372 by thenbrent (2013-12-13 22:27:13+00:00)
Title: Only allow a fee to be added once

When `WC_Cart->calculate_totals()` is run, order and line totals are effectively calculated from a base of 0. This allows plugins, like Subscriptions, to recalculate totals by call `WC_Cart->calculate_totals()` multiple times within the same request.

However, if `WC_Cart->add_fee()` is hooked to a function inside of `WC_Cart->calculate_totals()`, like `woocommerce_cart_calculate_fees`, then the fee will be added to the cart, even if it has already been added.

This patch prevents the same fee from being added more than once. It determines uniqueness using the psuedo-ID created by sanitising the fee's name. Therefore a plugin can still add a fee multiple times, but it would need to do be explicit to do so.

I'm not sure if there's a reason identical fees should be allowed to accumulate, and in any case, I've added a patch to Subscriptions to prevent duplicate fees (woothemes/woocommerce-subscriptions@08f9eac) so it won't affect it, but I preventing accumulation in core would avoid issues for other plugins that recalculate cart totals.