Search code examples
phpwordpresswoocommercewoocommerce-subscriptions

Woocommerce add fee to subscription renew


I have a function that when a user adds a teams subscription to their cart a fee is added depending on the number of seats they have for that team. When the user does this the first time there are no issues and the fee is applied correctly. However when the user tries to renew their teams membership/subscription no fee is added to their cart. I have checked all my logic and the code reaches the $cart->add_fee(‘Organization license yearly fee’, $price, true, ”); section where it should add the fee, yet no fee is added.

I am using the woocommerce_cart_calculate_fees hook which I believe is the correct one. This is also done using a action hook as opposed to a filter hook if that makes a differance.

I am completely stumped as to why the fee is not being added as it adds the fee when the user first buys the subscription.

Any and all help is greatly appreciated.


Solution

  • I managed to solve my problem by adding this filter.

    add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );